BookmarkSubscribeRSS Feed
gandikk
Obsidian | Level 7

Hi,

 

I have an input which has 3 fields.

 

10011438696014 222,160,539,533,265 Richard
10011438695678 246,187,739,563 Brian

 

I need to create an output based on the 2nd field like below. Comma is my delimiter in the 2nd field. I need to create duplicate records based on the comma separated values in the 2nd field.

 

10011438696014 222 Richard
10011438696014 160 Richard
10011438696014 539 Richard
10011438696014 533 Richard
10011438696014 265 Richard
10011438695678 246 Brian
10011438695678 187 Brian
10011438695678 739 Brian
10011438695678 563 Brian

 

How I can achieve this in SAS? Thanks in advance.

SAS@EMMAUS
2 REPLIES 2
novinosrin
Tourmaline | Level 20

Straight forward scan 

 

data have;
input (field1-field3) (:$50.);
cards;
10011438696014	222,160,539,533,265	Richard
10011438695678	246,187,739,563	Brian
;

data want;
set have;
do _n_=1 to countw(field2,',');
_field2=scan(field2,_n_,',');
output;
end;
drop field2;
run;
Reeza
Super User

COUNTW - how many words in the field

SCAN() to get ith element.

 

data want;
set have;

nwords  = countw(string);

do i=1 to nwords;
word =scan(string, i);
output;
end;

keep var1 word name;
run;

@gandikk wrote:

Hi,

 

I have an input which has 3 fields.

 

10011438696014 222,160,539,533,265 Richard
10011438695678 246,187,739,563 Brian

 

I need to create an output based on the 2nd field like below. Comma is my delimiter in the 2nd field. I need to create duplicate records based on the comma separated values in the 2nd field.

 

10011438696014 222 Richard
10011438696014 160 Richard
10011438696014 539 Richard
10011438696014 533 Richard
10011438696014 265 Richard
10011438695678 246 Brian
10011438695678 187 Brian
10011438695678 739 Brian
10011438695678 563 Brian

 

How I can achieve this in SAS? Thanks in advance.


 

SAS Innovate 2025: Register Now

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!

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
  • 802 views
  • 7 likes
  • 3 in conversation