Data I have:
1 A,B,C
2 D
3 E,F
Data I want:
1 A
1 B
1 C
3 E
3 F
data want; set have; do i = i to countw(string,','); newstring = scan(string,i,','); output; end; drop i string; run;
Set proper length for newstring as needed.
Welcome to the SAS Community 🙂
data have; input id var $20.; datalines; 1 A,B,C 2 D 3 E,F ; data want(keep=id newvar); set have; do i=1 to countw(var, ','); newvar=scan(var, i, ','); output; end; run;
Result:
id newvar 1 A 1 B 1 C 2 D 3 E 3 F
data have; infile cards dlm=' ,' truncover; input id var : $40. @; do while(not missing(var)); output; input var : $40. @; end; datalines; 1 A,B,C 2 D 3 E,F ;
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!
Submit your idea!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.