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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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