Hi all,
Quick question:
I have 2 datasets (ds1 and ds2) and they have some common variables (like ID, site name etc.) and some uncommon variables (flags and markers I have created in each)
Is there any way using proc SQL to create a new dataset - that sources from ds1 and ds2 and computes sums from different variables?
Example:
DS1 | DS2 | ||||
Site | Unit | var | Site | Unit | num |
A | P1 | 0 | A | P1 | 1 |
B | O1 | 1 | B | O1 | 1 |
B | O1 | 1 | B | O1 | 1 |
C | I1 | 0 | C | I1 | 0 |
C | I1 | 0 | C | I1 | 1 |
Final DS | |||||
Site | Unit | varsum | numsum | ||
A | P1 | 0 | 1 | ||
B | O1 | 2 | 2 | ||
C | I1 | 0 | 1 |
Try this :
proc sql;
select * from
(select ID, Unit, sum(var) as sumvar from ds1 group by ID, Unit) natural join
(select ID, Unit, sum(num) as sumnum from ds2 group by ID, Unit);
quit;
PG
Try this :
proc sql;
select * from
(select ID, Unit, sum(var) as sumvar from ds1 group by ID, Unit) natural join
(select ID, Unit, sum(num) as sumnum from ds2 group by ID, Unit);
quit;
PG
thanks! that works wonderfully well.
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.