How do I creatae a new sas dataset from one like the following:
HAVE:
| x1 | x2 | x3 | y1 | y2 | y3 | y4 |
| a | b | c | 33.7 | 29.2 | 34.4 | 31.4 |
WANT:
| x1 | x2 | x3 | y |
| a | b | c | 33.7 |
| a | b | c | 29.2 |
| a | b | c | 34.4 |
| a | b | c | 31.4 |
data have;
input x1 $ x2 $ x3 $ y1 y2 y3 y4;
cards;
a b c 33.7 29.2 34.4 31.4
run;
data want;
set have;
array _y[*] _numeric_;
do _n_= 1 to dim(_y);
y=_y[_n_]; output;
end;
drop y1 - y4;
run;
data have;
input (x1 x2 x3) ($) y1 y2 y3 y4;
cards;
a b c 33.7 29.2 34.4 31.4
;
proc transpose data=have out=want(drop=_name_ rename=col1=y);
by x1-x3;
var y1-y4;
run;
data have;
input x1 $ x2 $ x3 $ y1 y2 y3 y4;
cards;
a b c 33.7 29.2 34.4 31.4
run;
data want;
set have;
array _y[*] _numeric_;
do _n_= 1 to dim(_y);
y=_y[_n_]; output;
end;
drop y1 - y4;
run;
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 save with the early bird rate—just $795!
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.