BookmarkSubscribeRSS Feed
pw7632
Calcite | Level 5

proc sql noprint;
create table  baseball as
select a.Name , a.dob , a.gender , b.name, b.start, b.end

from salaries b inner join
TMP2.players a
on a.name = b.name;
quit;

 

I have a dataset that have the same values but different column names. a.Name , a.dob , a.gender all have different column names. How do I change them to make them the same as the b table? I also want the common variable to be name to join them. 

1 REPLY 1
Tom
Super User Tom
Super User

@pw7632 wrote:

proc sql noprint;
create table  baseball as
select a.Name , a.dob , a.gender , b.name, b.start, b.end

from salaries b inner join
TMP2.players a
on a.name = b.name;
quit;

 

I have a dataset that have the same values but different column names. a.Name , a.dob , a.gender all have different column names. How do I change them to make them the same as the b table? I also want the common variable to be name to join them. 


A SAS dataset  cannot have two variable with the same name.  So in your example code the second variable named NAME is not going to be written.  Just provide new name in the select statement.  There is no need for two copies of NAME since your join is requiring them to be the same value.  But if both dataset had DOB and GENDER for example you could select both and rename one of them.

create table baseball as
 select a.Name 
      , a.dob 
      , a.gender 
      , b.dob as dob2
      , b.gender as gender2
      , b.start
      , b.end
 from salaries b
   inner join TMP2.players a
   on a.name = b.name
;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 2022 views
  • 0 likes
  • 2 in conversation