Hi,
I am trying to transpose a data set from "Wide to Long".
The numeric variables (to be transposed based on a BY variable group) in the initial WIDE dataset have names F2,F3,F4,.....F20
After the transposition, in the new _NAME_ variable I would like to have the above names RENAMED as follows
12
24
36
...
...
228
(i.e. starting F2=12 F3=24 ...F20= 228 - incrementing by 12)
Any suggestions would be more than welcomed.
Thank you
Nikos
another way:
data have;
input f2-f20;
cards;
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
;
proc transpose out=temp;
var f:;
run;
data want (rename =v=_name_);
set temp;
v=(input(compress(_name_,'f','U'),2.)-1)*12;
drop _:;
proc print;run;
Obs COL1 _name_
1 2 12
2 3 24
3 4 36
4 5 48
5 6 60
6 7 72
7 8 84
8 9 96
9 10 108
10 11 120
11 12 132
12 13 144
13 14 156
14 15 168
15 16 180
16 17 192
17 18 204
18 19 216
19 20 228
Not sure if I understand what you asked for:
data have;
array ff f2-f20;
do _n_=1 by 1 to dim(ff);
ff(_n_)=12*_n_;
end;
run;
proc transpose data=have out=want (drop=_name_ rename=col1=_name_);
var f2-f20;
run;
proc print;run;
Regards,
Haikuo
data want(drop=_NAME_);
set have;
newVar = 12*(input(substr(_NAME_,2),2.)-1);
run;
PG
Hi,
I would like to thank you
Nikos
another way:
data have;
input f2-f20;
cards;
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
;
proc transpose out=temp;
var f:;
run;
data want (rename =v=_name_);
set temp;
v=(input(compress(_name_,'f','U'),2.)-1)*12;
drop _:;
proc print;run;
Obs COL1 _name_
1 2 12
2 3 24
3 4 36
4 5 48
5 6 60
6 7 72
7 8 84
8 9 96
9 10 108
10 11 120
11 12 132
12 13 144
13 14 156
14 15 168
15 16 180
16 17 192
17 18 204
18 19 216
19 20 228
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.