DATA Step, Macro, Functions and more

How do I combine the data using PROC SQL

Reply
Occasional Contributor nrb
Occasional Contributor
Posts: 11

How do I combine the data using PROC SQL

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. 

 

Super User
Posts: 19,770

Re: How do I combine the data using PROC SQL

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

 

 

Super Contributor
Posts: 266

Re: How do I combine the data using PROC SQL

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.

 

Ask a Question
Discussion stats
  • 2 replies
  • 136 views
  • 1 like
  • 3 in conversation