BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
r3570
Obsidian | Level 7

Hi All,

 

I have a dataset as below with variables A, B, C, D

 

A          B         C          D

XYZ    1,2,3   PQR    YZA

 

I need output as below

 

A          B         C          D

XYZ     1      PQR        YZA

XYZ     2      PQR        YZA

XYZ     3      PQR        YZA

 

Kindly help

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Here one way to go.

data have;
  input (A B C D) ($);
  datalines;
XYZ 1,2,3 PQR YZA
;

data want(drop=_:);
  set have;
  _stop=sum(countc(b,','),1);
  _b=b;
  do _i=1 to _stop;
    b=scan(_b,_i);
    output;
  end;
run;

Patrick_0-1632302647392.png

 

View solution in original post

2 REPLIES 2
Patrick
Opal | Level 21

Here one way to go.

data have;
  input (A B C D) ($);
  datalines;
XYZ 1,2,3 PQR YZA
;

data want(drop=_:);
  set have;
  _stop=sum(countc(b,','),1);
  _b=b;
  do _i=1 to _stop;
    b=scan(_b,_i);
    output;
  end;
run;

Patrick_0-1632302647392.png

 

maguiremq
SAS Super FREQ

Also, here's another way to do it.

 

data have;
  input (A B C D) ($);
  datalines;
XYZ 1,2,3 PQR YZA
;

data want (drop = bb i);
	retain a b c d;
	set have (rename = (b = bb));
	do i = 1 to countw(bb, ",");
		b = scan(bb, i, ",");
		output;
	end;
run;
a b c d 
XYZ 1 PQR YZA 
XYZ 2 PQR YZA 
XYZ 3 PQR YZA 
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
  • 974 views
  • 0 likes
  • 3 in conversation