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 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 352 views
  • 0 likes
  • 3 in conversation