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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.