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 ;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
Register now!
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.