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
SAS Super FREQ

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

sas-innovate-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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