BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
vomer
Obsidian | Level 7

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:

DS1DS2
SiteUnitvarSiteUnitnum
AP10AP11
BO11BO11
BO11BO11
CI10CI10
CI10CI11
Final DS
SiteUnitvarsumnumsum
AP101
BO122
CI101
1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

PG

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

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

PG
vomer
Obsidian | Level 7

thanks! that works wonderfully well.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1306 views
  • 0 likes
  • 2 in conversation