BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dennis_oz
Quartz | Level 8
hi all , please can you help me with this requirement
thanks in advance.
input dataset

Id claim_list
----- -----------------
abc 123, 456 ,789
def
ghi 111,222,333

my output requirement:

id claim_id
abc 123
abc 456
abc 789
def
ghi 111
ghi 222
ghi 333
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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   

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

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   
dennis_oz
Quartz | Level 8
thanks for this . deeply appreciated

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 765 views
  • 0 likes
  • 2 in conversation