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 ;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Latest Updates
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.