Use countw(), scan(), and a conditional do loop:
data have;
infile datalines truncover;
input Id $ claim_list :$20.;
datalines;
abc 123,456,789
def
ghi 111,222,333
;
data want;
set have;
length claim_id $3;
if countw(claim_list,',') > 0
then do i = 1 to countw(claim_list,',');
claim_id = scan(claim_list,i,',');
output;
end;
else output;
keep id claim_id;
run;
proc print data=want noobs;
run;
Result:
Id claim_id abc 123 abc 456 abc 789 def ghi 111 ghi 222 ghi 333
Use countw(), scan(), and a conditional do loop:
data have;
infile datalines truncover;
input Id $ claim_list :$20.;
datalines;
abc 123,456,789
def
ghi 111,222,333
;
data want;
set have;
length claim_id $3;
if countw(claim_list,',') > 0
then do i = 1 to countw(claim_list,',');
claim_id = scan(claim_list,i,',');
output;
end;
else output;
keep id claim_id;
run;
proc print data=want noobs;
run;
Result:
Id claim_id abc 123 abc 456 abc 789 def ghi 111 ghi 222 ghi 333
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.