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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.