Hello
Please find following code in proc sql.
I want to ask please what type of join is done here?
Inner join? full join? left join? right join?
Why If I write - on survey.Answer=survey2.Answer I receive an error?
and it only works with - where survey.Answer=survey2.Answer ?
data survey;
input State $ Answer $ @@;
datalines;
NY YES NY YES NY YES NY YES NY YES NY YES NY NO NY NO NY NO NC YES
NC YES NC YES NC YES NC YES NC YES NC YES NC YES NC YES NC YES NC YES
NC YES NC YES NC YES NC YES NC YES NC YES NC YES NC YES NC YES NC NO
NC NO NC NO NC NO NC NO NC NO NC NO NC NO NC NO NC NO NC NO
NC NO NC NO NC NO NC NO NC NO NC NO NC NO NC NO NC NO NC NO
NC NO NC NO NC NO PA YES PA YES PA YES PA YES PA YES PA YES PA YES
PA YES PA YES PA NO PA NO PA NO PA NO PA NO PA NO PA NO PA NO
PA NO PA NO PA NO PA NO PA NO PA NO PA NO PA NO PA NO PA NO
VA YES VA YES VA YES VA YES VA YES VA YES VA YES VA YES VA YES VA YES
VA YES VA YES VA YES VA YES VA YES VA YES VA YES VA YES VA YES VA NO
VA NO VA NO VA NO VA NO VA NO VA NO VA NO VA NO VA NO VA NO
VA NO VA NO VA NO VA NO VA NO VA NO
;
Run;
proc sql;
title1 'Survey Responses';
select survey.Answer, survey.State,
count(*) as Count,
calculated Count/Subtotal as Percent format=percent8.2
from survey,
(select Answer,
count(*) as Subtotal
from survey
group by Answer) as survey2
where survey.Answer=survey2.Answer
group by survey.Answer, survey.State;
quit;
Interesting question, never really thought about parallels. The on keyword will not work as no join is specified. The join is based on the where clause, so only data where answer is in both datasets would be output, so inner join effectively.
Interesting question, never really thought about parallels. The on keyword will not work as no join is specified. The join is based on the where clause, so only data where answer is in both datasets would be output, so inner join effectively.
Thanks a lot.]
So it is just another way to write inner join .(using comma instead of writing inner join and using where instead of on).
It is an equivalent program
proc sql;
title1 'Survey Responses';
select a.Answer, a.State,
count(*) as Count,
calculated Count/Subtotal as Percent format=percent8.2
from survey as a
inner join (select Answer,
count(*) as Subtotal
from survey
group by Answer) as b
on a.Answer=b.Answer
group by a.Answer, a.State;
quit;
Yes, should be. You can always try it...
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.