BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Bal23
Lapis Lazuli | Level 10
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.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Assuming you do not have spaces before the numbers in question

 

Variable = substr(variable,index(variable,' ')+1);

 

might work.

View solution in original post

3 REPLIES 3
ballardw
Super User

Assuming you do not have spaces before the numbers in question

 

Variable = substr(variable,index(variable,' ')+1);

 

might work.

SASJedi
Ammonite | Level 13

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
Check out my Jedi SAS Tricks for SAS Users

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 5508 views
  • 2 likes
  • 3 in conversation