Here is a sample data set where column 1 is the ID which has the employees name and number
I only want the numbers to be outputted
ID | Date | Amount |
Robert, Andrews 222-22-1234 | 2019 | 1,234.00 |
Albert, Sanders 123-45-6789 | 2018 | 2,34.67 |
Zack, Snyder 111-22-3333 | 2020 | 1,234.77 |
I need the following output
ID | Date | Amount |
222-22-1234 | 2019 | 1,234.00 |
123-45-6789 | 2018 | 2,34.67 |
111-22-3333 | 2020 | 1,234.77 |
input ID : $12
Year : Year.
Amount: comma13.
;
Please let me know how to only the ID numbers in the output table no names.
Thanks
A very simple way would be to use the anydigit() function inside the substr() function .
There are several ways you can do this:
I am sure that after having the a quick look at the documentation of the functions, you are able to solve the problem. If not, please post data in usable form and the code you already have.
can you provide me the compress function code to get only the number and hypen.
What have you tried? Being able to read the docs and find required information is a necessary skill to learn a programming language.
Your ID has a clear pattern for a SCAN function starting from right to left-
length want_id $15;
want_id=scan(id,-1,' ');
data have ;
infile cards truncover expandtabs ;
input ID $28. Date Amount :comma10. ;
format amount comma10.2 ;
cards;
Robert, Andrews 222-22-1234 2019 1,234.00
Albert, Sanders 123-45-6789 2018 2,34.67
Zack, Snyder 111-22-3333 2020 1,234.77
;
data want ;
set have ;
length want_id $15 ;
want_id=scan(id,-1,' ') ;
run ;
proc print noobs ; run ;
ID | Date | Amount | want_id |
---|---|---|---|
Robert, Andrews 222-22-1234 | 2019 | 1,234.00 | 222-22-1234 |
Albert, Sanders 123-45-6789 | 2018 | 234.67 | 123-45-6789 |
Zack, Snyder 111-22-3333 | 2020 | 1,234.77 | 111-22-3333 |
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.