How about this code?
data have;
length Id 8 ict $8;
infile datalines dlm=' ';
input id ict;
datalines;
102 4
103 5,7
;
run;
data want;
set have;
tmp_cnt=count(ict,',')+1;
tmp_ict=ict;
do i=1 to tmp_cnt;
ict=scan(tmp_ict,i,',');
output;
end;
drop tmp_: i;
run;
(modified.)
You can simplify this with the use of dataset options and use of the COUNTW function in the DO statement:
data want;
set have (rename=(ict=_ict));
do i = 1 to countw(_ict,",");
ict = scan(_ict,i,",");
output;
end;
drop i _ict;
run;
PS if you want numbers, add an INPUT function:
data want;
set have (rename=(ict=_ict));
do i = 1 to countw(_ict,",");
ict = input(scan(_ict,i,","),32.);
output;
end;
drop i _ict;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.