BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Nikos
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

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

View solution in original post

4 REPLIES 4
Haikuo
Onyx | Level 15

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

PGStats
Opal | Level 21

data want(drop=_NAME_);

set have;

newVar = 12*(input(substr(_NAME_,2),2.)-1);

run;

PG

PG
Nikos
Fluorite | Level 6

Hi,

I would like to thank you

Nikos

Linlin
Lapis Lazuli | Level 10

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1475 views
  • 3 likes
  • 4 in conversation