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
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;
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;
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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.