Solved
Contributor
Posts: 68

# Rename an array of var names after a "Wide to Long" transpose

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

Accepted Solutions
Solution
‎03-15-2012 12:41 PM
Super Contributor
Posts: 1,636

## Re: Rename an array of var names after a "Wide to Long" transpose

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

All Replies
Posts: 3,167

## Rename an array of var names after a "Wide to Long" transpose

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

Posts: 5,523

## Rename an array of var names after a "Wide to Long" transpose

data want(drop=_NAME_);

set have;

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

run;

PG

PG
Contributor
Posts: 68

## Rename an array of var names after a "Wide to Long" transpose

Hi,

I would like to thank you

Nikos

Solution
‎03-15-2012 12:41 PM
Super Contributor
Posts: 1,636

## Re: Rename an array of var names after a "Wide to Long" transpose

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

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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