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;
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!
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.