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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.