Help using Base SAS procedures

Creating new data set from 2 seperate datasets (SQL)

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 117
Accepted Solution

Creating new data set from 2 seperate datasets (SQL)

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

Accepted Solutions
Solution
‎03-20-2013 10:40 AM
Respected Advisor
Posts: 4,920

Re: Creating new data set from 2 seperate datasets (SQL)

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


All Replies
Solution
‎03-20-2013 10:40 AM
Respected Advisor
Posts: 4,920

Re: Creating new data set from 2 seperate datasets (SQL)

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
Frequent Contributor
Posts: 117

Re: Creating new data set from 2 seperate datasets (SQL)

thanks! that works wonderfully well.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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