Presentation is loading. Please wait.

Presentation is loading. Please wait.

UNION Operator keywords Displays all rows from both the tables

Similar presentations


Presentation on theme: "UNION Operator keywords Displays all rows from both the tables"— Presentation transcript:

1 UNION Operator keywords Displays all rows from both the tables
Removes duplicate records from the combined dataset keywords  ALL -- duplicate rows in the combined dataset.  CORR   -- PROC SQL matches the columns by name.

2 Remove nonmatching columns.
UNION Operator UNION CORR ALL Remove duplicate rows. No Yes End Concatenate tables. Remove nonmatching columns.

3 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 /*union*/ proc sql; select * from t1 union from t2 ; quit;

5 /*reverse order of union*/
proc sql; select * from t2 union from t1 ; quit;

6 /*create a table from union*/
proc sql; create table tot1 as select * from t1 union from t2 ; quit; proc print data=tot1;run;

7 /*the corr option*/ proc sql; select * from t2 union corr from t1 ; quit;

8 /*the all option*/ proc sql; select * from t2 union all from t1 ; quit;

9 /*both corr and all*/ proc sql; select * from t2 union corr all from t1 ; quit;

10 Payroll Report for Level I, II, and III Employees
Create a payroll report for the Level I, II, and III Orion Star employees. The orion.Staff table contains the job title and salary information for all Orion Star employees. Use the UNION set operator to combine the results from each query that calculates the total paid to all Level I, II, and III employees. Payroll Report for Level I, II, and III Employees _______________________________________ Total Paid to ALL Level I Staff ,234, Total Paid to ALL Level II Staff ,456, Total Paid to ALL Level III Staff 2,123,456

11 The UNION Operator proc sql; select 'Total Paid to ALL Level I Staff',
sum(Salary) format=comma12. from orion.Staff where scan(Job_Title,-1, ' ')='I' union select 'Total Paid to ALL Level II Staff', where scan(Job_Title,-1,' ')='II' select 'Total Paid to ALL Level III Staff', where scan(Job_Title,-1,' ')='III'; quit; s106d11

12 Remove nonmatching columns.
UNION Operator UNION CORR ALL Remove duplicate rows. No Yes End Concatenate tables. Remove nonmatching columns.


Download ppt "UNION Operator keywords Displays all rows from both the tables"

Similar presentations


Ads by Google