Hello,
I would like to remove the letters in the dataset below.
Data Have;
input id;
1111-000001KK
1111-000002IM
1111-000003IM
1111-000011IM
1111-000111IM
1111-000221IM
1111-000331IM
1111-000441IM
1111-000002IM
IM-1111-000644
IM-1111-001264
IM-1111-001613
IM-1111-001630
IM-1111-001632
IM-2222-001825
IM-1111-001931
IM-1111-002029
IM-1111-002270
IM-3333-002387;
run;
Can anyone guide me as how to accomplish this task so the id variable has only numbers, as in Dataset Want?
Data want;
1111-000001
1111-000002
1111-000003
1111-000011
1111-000111
1111-000221
1111-000331
1111-000441
1111-000002
1111-000644
1111-001264
1111-001613
1111-001630
1111-001632
2222-001825
1111-001931
1111-002029
1111-002270
3333-002387
Thank you.
Use the COMPRESS() function instead of SUBSTR.
That will remove all the letters, but you'll have to check if you end up with a leading or trailing - that needs to be removed.
You can use SUBSTR() for that, along with CHAR() to check the first/last character.
x = compress(string, , 'a');
List of SAS functions are available here:
Use the COMPRESS() function instead of SUBSTR.
That will remove all the letters, but you'll have to check if you end up with a leading or trailing - that needs to be removed.
You can use SUBSTR() for that, along with CHAR() to check the first/last character.
x = compress(string, , 'a');
List of SAS functions are available here:
Data Have;
input id $20.;
cards;
1111-000001KK
1111-000002IM
1111-000003IM
1111-000011IM
1111-000111IM
1111-000221IM
1111-000331IM
1111-000441IM
1111-000002IM
IM-1111-000644
IM-1111-001264
IM-1111-001613
IM-1111-001630
IM-1111-001632
IM-2222-001825
IM-1111-001931
IM-1111-002029
IM-1111-002270
IM-3333-002387
;
run;
data want;
set have;
t=compress(id,' ','a');
id=ifc(length(t)>11,substr(t,2),t);
drop t;
run;
Hello,
Here is one solution
Data Have;
input id $20.;
id=prxchange("s/-?[A-Z]-?//",-1,id);
cards;
1111-000001KK
1111-000002IM
1111-000003IM
1111-000011IM
1111-000111IM
1111-000221IM
1111-000331IM
1111-000441IM
1111-000002IM
IM-1111-000644
IM-1111-001264
IM-1111-001613
IM-1111-001630
IM-1111-001632
IM-2222-001825
IM-1111-001931
IM-1111-002029
IM-1111-002270
IM-3333-002387
;
run;
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.