length id val $200;
input id val ;
/*output should be
I tried using the scan function but it doesn't work. I am trying to separate the values after the commas to a new variable as listed above
If you tried using the SCAN function and it doesn't work ... show us what you did. Show us the SASLOG so we can see your code and error messages.
HINT: Don't ever tell us "it doesn't work" without additional explanation because that's not enough information for us to help you. Explain! Show us the SASLOG.
Thats overthinking it. A simple change to the import program eliminates the need for post processing at all:
data one; infile datalines dlm=" ,"; length id val1 val2 val3 val4 8; input id val1--val4; datalines; 1 3,8,9,8 2 3,8,9,8 ; run;
So the solution by @novinosrin seems to work if you can guarantee that the numbers in the original data set are integers between 0 and 9. It will not work if the numbers are 10 or higher; it will not work for negative numbers and it will not work for non-integers.
@PaigeMiller Thank you for waking me up.
Revised to address -ve and higher digits
data one; length id val $200; input id val ; datalines; 1 -3,8888,9,-80 2 39,88,9,8 ; run; data want; set one; length want $20.; do n=1 to countw(val,','); want=scan(val,n,','); output; end; keep id want; run;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.