2.1 Child Conditions
2.2 Teenage Conditions
2.3 Adult Conditions
2.4 Senior Conditions
I need to modify this variable, by deleting 2.1, 2.2 etc. and keep Child conditions etc. The lengths of the words left are not same.
The desired var2 should be
Child conditions
teenage conditions
adult conditions
senior conditions
Compress can only remove ., any advice how to remove the first numbers?
Thanks.
Assuming you do not have spaces before the numbers in question
Variable = substr(variable,index(variable,' ')+1);
might work.
Assuming you do not have spaces before the numbers in question
Variable = substr(variable,index(variable,' ')+1);
might work.
Thanks
Actually, COMPRESS with the appropriate modifiers could handle this particular problem very nicely 🙂 The third argument accepts modifiers to change the behavior of COMPRESS. In this case, I'd use 'k' for KEEP (instead of the default REMOVE behavior) and add an 'a' to specify ALPHABETIC characters along with 's' to specify SPACE characters. The STRIP function gets rid of any leading spaces.
The result:
data test;
length Original Fixed $ 30;
infile datalines dsd;
input Original;
Fixed=strip(compress(original,,'kas'));
put original=$quote. Fixed=$quote.;
datalines;
2.1 Child Conditions
2.2 Teenage Conditions
2.3 Adult Conditions
2.4 Senior Conditions
;
Result:
Obs | Original | Fixed |
---|---|---|
1 | 2.1 Child Conditions | Child Conditions |
2 | 2.2 Teenage Conditions | Teenage Conditions |
3 | 2.3 Adult Conditions | Adult Conditions |
4 | 2.4 Senior Conditions | Senior Conditions |
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.