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

sas-innovate-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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