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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.