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!
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.
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;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.