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.
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.
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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.