BookmarkSubscribeRSS Feed
nrb
Fluorite | Level 6 nrb
Fluorite | Level 6

I have the following data 

data left;

input subj Height Weight;

cards;

001 68 155

002 75 220

003 65 99

005 79 266

006 70 190

009 61 122

;

data right;

input subj salary;

datalines;

001 46000

003 67900

004 28200

005 98202

006 88000

007 57200

;

 

a. I want to use  Proc SQL to create a new SAS data set containing Subj (both Subj variables), Height, Weight and Salary, I know I have to rename Subj from the left data set as LeftSubj and rename Subj from the right data set as RightSubj in Proc SQL, however i'm not sure how to do this. When I do it on my own the output doesn't come out right. 

 

2 REPLIES 2
Reeza
Super User

Why not post what you've tried and we can suggest modifications?

 

It's good to know what didn't work with your methodology.

 

The SAS documentation has a list of all the different ways of combining data and code on how to accomplish each method.

 

http://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#p15jvywi5avt3cn1bee8...

 

 

RahulG
Barite | Level 11

Try below code. 

proc sql;
create table want as
select a.subj
, a.height
, a.Weight
, b.salary
from left a 
inner join 
right b 
on a.subj = b.subj;
quit;

Try changing key inner join to left join or right join to get desired result. 

Link shared by @Reeza must read to understand the concept.

 

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
  • 2 replies
  • 719 views
  • 1 like
  • 3 in conversation