BookmarkSubscribeRSS Feed
savyj88
Calcite | Level 5

Hi SAS community, 

 

I have a variable in a dataset called "id" (short for identification). 

 

Observations under this variable are recorded as such: 001AB, 002DK, 003LB, 004KC, etc.  

 

For clarification, the numeric digits refer to the participant number, while the letters refer to the initials of the individual participant in question. 

 

I would simply like to "get rid" of the letters within these id's. 

 

Therefore, 001AB would become simply 001, 002DK would simply become 002, and so forth. 

 

Could anyone point me in the right direction for a solution to this problem?

 

Many thanks!

 

 

2 REPLIES 2
Tom
Super User Tom
Super User

Look at the modifiers on the COMPRESS() function.

https://documentation.sas.com/doc/en/vdmmlcdc/1.0/lefunctionsref/n0fcshr0ir3h73n1b845c4aq58hz.htm

data want;
  set have;
  id = compress(id,,'kd');
run;
284   data want;
285     set have;
286     put id= @;
287     id = compress(id,,'kd');
288     put '-> ' id ;
289   run;

id=001AB -> 001
id=002DK -> 002
id=003LB -> 003
id=004KC -> 004
NOTE: There were 4 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 4 observations and 1 variables.
GraphGuy
Meteorite | Level 14

Here's one way to do it ...

 

data foo;
id='001RA';
run;

data foo; set foo;
id=substr(id,1,length(id)-2);
run;

proc print data=foo;
run;

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 455 views
  • 0 likes
  • 3 in conversation