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.
A an B are in same data set red2.
X is dataset red
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;
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).
both A and B belong to same dataset red2....where as X belong to red.
red red2
X A B
red
X
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
thanxs.. i got it using your way.
but i lost other variables in have.
how can i retain other variables???
Lots of good responses here. Nice to see some interesting ideas for the same problem!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.