Download presentation
Presentation is loading. Please wait.
1
The INTERSECT Operator
5 The INTERSECT Operator Common unique rows from both result sets are selected.
2
Flow Diagram: INTERSECT Operator
CORR Yes Remove nonmatching columns. No ALL No Yes Remove duplicate rows. Save matching rows. End
3
Example Data Sets data t1(drop=i) t2(drop=i rename=(z=w));
call streaminit(13453); do i= 1 to 3; x=int(rand("uniform")*5); z=int(rand("uniform")*5); output t1; output t2; end; do i= 4 to 6; run; data t1; set t1 end=done; output; if done then output; data t2; set t2 end=done; if _n_=1 then output; title "t1"; proc print data=t1 noobs;run; title "t2"; proc print data=t2 noobs;run; title;
4
proc sql; select * from t1 intersect from t2 ; quit;
5
proc sql; select * from t1 intersect corr from t2 ; quit;
6
proc sql; select * from t1 intersect all from t2 ; quit;
7
Orion Star frequently hires experienced Sales staff at higher levels on the assumption that they will be more productive than inexperienced personnel. Create a report that displays the employee identification number of current Level III and Level IV Sales staff hired in 2004, who made at least one sale by the end of 2005. orion.Order_fact table contains information on all sales. orion.Sales table contains information about current Sales employees, including job titles and hire dates.
8
The INTERSECT Operator
Need a query that returns information from rows that exist in both orion.Sales and orion.Order_fact. sales by Sales staff
9
Create a report that displays the employee identification number of current Level III and Level IV Sales staff hired in 2004, who made at least one sale by the end of 2005. proc sql; select Employee_ID from orion.Sales where year(Hire_date)=2004 and scan(Job_Title,-1) in ("III","IV") intersect all select distinct Employee_ID from orion.Order_fact where year(Order_date) le 2005; quit; s106d08
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.