BookmarkSubscribeRSS Feed
debabrata
Calcite | Level 5

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.

 

8 REPLIES 8
gauthamk28
Obsidian | Level 7
Is the variable A from red and B from red 2 dataset???
debabrata
Calcite | Level 5

A an B are in same data set red2.

X is dataset red

thomp7050
Pyrite | Level 9

 

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;

 

Astounding
PROC Star

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).

debabrata
Calcite | Level 5

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

 

red    red2

X       A   B

 

red

X

Tom
Super User Tom
Super User

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
debabrata
Calcite | Level 5

thanxs.. i got it using your way.

but i lost other variables in have.

 

how can i retain other variables???

thomp7050
Pyrite | Level 9

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 8 replies
  • 1560 views
  • 3 likes
  • 5 in conversation