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 |
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.