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
;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1 reply
  • 1374 views
  • 0 likes
  • 2 in conversation