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

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;


 
1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Ronein
Meteorite | Level 14

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;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, should be.  You can always try it...

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 738 views
  • 1 like
  • 2 in conversation