I just want to double check my thinking on this... When using multiple set operators in SQL in a single SQL statement, are the actions performed incrementally?
For example, I have in my code:
proc sql;
select distinct vv.naics_code
from eds.pt_naic_codes as vv
union
select distinct loc.naics_code
from eds.pa_location as loc
union
select distinct qcew.naics_code_pt_naic_codes as naics_code
from eds.ps_qcew_data as qcew
except
select sched.naics_code
from eds.ps_scheduling_naics as sched;
quit;
and I want it to work so that it appends the first three tables before excluding the fourth table.
As written, will I be getting what I expect?
The most reliable place to look is the SAS documentation which says:
"A query expression with set operators is evaluated as follows.
Parentheses may be your friend to help control "order".
Perhaps:
proc sql; ( select distinct vv.naics_code from eds.pt_naic_codes as vv union select distinct loc.naics_code from eds.pa_location as loc union select distinct qcew.naics_code_pt_naic_codes as naics_code from eds.ps_qcew_data as qcew ) except select sched.naics_code from eds.ps_scheduling_naics as sched; quit;
The most reliable place to look is the SAS documentation which says:
"A query expression with set operators is evaluated as follows.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.