DATA Step, Macro, Functions and more

rename error

Reply
Occasional Contributor
Posts: 5

rename error

hi 

 

i am trying to rename two variables with different names as same new name

for ex:

 

rename A as x and rename B as X in same data set.

i m performing concatenationof 2 data set using "set" and trying to rename the variables A, B as X(original name in one data set);

i am writing code as:

 

Set red red2 (rename=(A = x));....working

Set red red2 (rename=(A=x B=x));......not working.

 

any suggestion.

 

Contributor
Posts: 21

Re: rename error

Posted in reply to debabrata
Is the variable A from red and B from red 2 dataset???
Occasional Contributor
Posts: 5

Re: rename error

Posted in reply to gauthamk28

A an B are in same data set red2.

X is dataset red

Frequent Contributor
Posts: 93

Re: rename error

Posted in reply to debabrata

 

proc sql;
create table mytable as
select var1 as myvar1, var2 as myvar2, var3 as myvar3
from red
union all
select var1, var2, var3 from red2;
quit;

 

Super User
Posts: 5,497

Re: rename error

Posted in reply to debabrata

Each data set named can have its own data set options.  So this might be what you are looking for:

 

 

set red (rename=(b=X)) red2 (rename=(a=X));

 

If this is the right idea, it would be a requirement that A and B are the same type (either both numeric, or both character).

Occasional Contributor
Posts: 5

Re: rename error

Posted in reply to Astounding

both A and B belong to same dataset red2....where as X belong to red.

 

red    red2

X       A   B

 

red

X

Super User
Super User
Posts: 7,039

Re: rename error

Posted in reply to debabrata

Sounds like you want to tranpose the data to convert two columns into two rows.

But for this simple example just set the original dataset twice.

 

data want ;
  set have (keep=A rename=(A=X)) have (keep=B rename=(B=X)) ;
run;

So if you had:

A B
1 2
3 4
5 6

You would get

X
1
3
5
2
4
6
Occasional Contributor
Posts: 5

Re: rename error

thanxs.. i got it using your way.

but i lost other variables in have.

 

how can i retain other variables???

Frequent Contributor
Posts: 93

Re: rename error

Posted in reply to debabrata

Lots of good responses here.  Nice to see some interesting ideas for the same problem!

Ask a Question
Discussion stats
  • 8 replies
  • 131 views
  • 3 likes
  • 5 in conversation