August 07, 2007, 05:06 PM
<M_RIOS75>EDIT Question - extracting characters
I would use the following code to extract the last 2 characters for the field I need which in this case FIELD1=A10
FIELD2/A2 = EDIT(FIELD1,'$$$$$$$$99');
But the field value I'm working with can be anywhere from A10 to A28 (field is A28), how can I make this dynamic; pulling off the last 2 characters on that field?
August 07, 2007, 05:27 PM
JimRiceHi Marvin,
Here's an example using the CAR file and the CAR field(A16).
-*
DEFINE FILE CAR
RJUST_CAR/A16 = RJUST(16, CAR, RJUST_CAR);
LAST2_CAR/A2 = EDIT(RJUST_CAR,'$$$$$$$$$$$$$$99');
END
-*
TABLE FILE CAR
PRINT
CAR
RJUST_CAR
LAST2_CAR
BY COUNTRY
END
-*
Jim
August 07, 2007, 05:34 PM
AlanUsing Functions Pg. 5-54 :
DEFINE FILE ...
-*** First trim the trailing blanks...
FLD1_TRIM/A28V = TRIMV('T', ORIGINAL_FLD, 28, ' ', 1, FLD1);
-*** Then find the true length of the data...
FLD1_LGTH/I2 = LENV(FLD1_TRIM, FLD1_LGTH);
-*** Calculate the Starting Position...
FLD1_START/I2 = FLD1_LGTH - 2 ;
-*** Substring to get the result...
FLD1_LAST2/A2 = SUBSTV(28, ORIGINAL_FLD, FLD1_START, FLD1_LGTH, FLD1_LAST2);
END
August 08, 2007, 10:17 AM
<M_RIOS75>Thanks for the replies! I found the first response easier to follow although they were both helpful. Thanks again.