December 14, 2005, 03:58 PM
dhofmanRemoving Embedded spaces
I have an alphanumeric field that has spaces between significant digits that can occur any place within that field (ie. no set postion in the field). Is there a way to remove the embedded spaces, basically smashing everything together? I figured out how to remove them before or after significant digits, but not when they are in the middle.
Hopefully someone can help. Thanks
December 14, 2005, 04:34 PM
jimster06In the Technical Documenation Library above, search for STRIP.
December 14, 2005, 05:00 PM
smithsHere's one method using SUBSTR. Loop through your string a character at a time, and build a new string based on the non-blank characters.
-* Set initial value to be parsed
-SET &FIELD = ' 12 3 xxx 456 7 8 9 ';
-* Get the length of the field
-SET &FIELD_LEN = &FIELD.LENGTH;
-* Set the field format
-SET &FIELD_FMT = 'A' | &FIELD_LEN;
-* Initialize the field that will store the parsed field
-SET &NEWSTR = '';
-* Initialize the loop index
-SET &IDX = 1;
-* Iterate through the number (&FIELD)
-REPEAT :ENDLOOP WHILE &IDX LE &FIELD_LEN;
-* Get the next character in the string
-SET &CHARACTER = SUBSTR(&FIELD_LEN, &FIELD, &IDX,
- &IDX, 1, 'A1');
-* If a non-blank is found, append it to the new
-* string, otherwise do nothing
-SET &NEWSTR = IF (&CHARACTER NE ' ') THEN &NEWSTR || &CHARACTER
-ELSE &NEWSTR;
-* Advance to the next character
-SET &IDX = &IDX + 1;
-:ENDLOOP
-* Remove trailing space
-SET &NEWSTR = TRUNCATE(&NEWSTR);
-* Here's the final value
-TYPE NEWSTR: (&NEWSTR)
December 14, 2005, 06:59 PM
susannahand SQUEEZ function will smash multiple blanks to a single blank, might be a good way to start.
December 14, 2005, 08:02 PM
MikelAs
jimster06 said, I think
STRIP function is the right option.
TABLE FILE CAR
PRINT
COMPUTE TEST1/A15 = ' 1 2 3 5. 6 5' ;
COMPUTE TEST2/A15 = STRIP(15, TEST1, ' ', TEST2);
COMPUTE TEST3/D15.2 = ATODBL(TEST2, '15', TEST3);
COUNTRY
IF READLIMIT EQ 1
END
-RUN
Regards,
Mikel
December 15, 2005, 10:43 AM
dhofmanEveryone,
Thanks for your help. I have it working great with a the Strip function. I really need to get some updated manuals!!