Using the OUTER UNION Set Operator

A Brief Overview

The set operator OUTER UNION concatenates the results of the queries:
  • It selects all rows (both unique and nonunique) from both tables.
  • It does not overlay columns.
Figure 4.6 Outer Union Set Operator Relationship
Outer Union Set Operator Relationship
The following examples demonstrate how OUTER UNION works when used alone and with the keyword CORR. The keyword ALL is not used with OUTER UNION because this operator's default action is to include all rows in output.

Example: Using the OUTER UNION Operator Alone

Suppose you want to display all rows from both of the tables Col1 and Col2, without overlaying columns.
proc sql;
   select *
      from certadv.col1 outer union
   select *
      from certadv.col2;
quit;
Output 4.23 PROC SQL Query Result Illustration
Tables Col1, Col2, Output
In the output, the columns have not been overlaid. Instead, all four columns from both tables are displayed. Each row of output contains missing values in the two columns that correspond to the other table.

Example: Using the Keyword CORR with One OUTER UNION Operator

The output from the preceding set operation contains two columns with the same name. To overlay the columns with a common name, add the keyword CORR to the set operation:
proc sql;
   select *
      from certadv.col1 outer union corr
   select *
      from certadv.col2
;
quit;
The output from the modified set operation contains only three columns because the two columns named X are overlaid.
Output 4.24 PROC SQL Query Result Illustration
Tables Col1, Col2, Output

Example: Using Two OUTER UNION Operators with the Keyword CORR

Suppose you want to display the employee ID numbers, job codes, and salaries of all mechanics working for an airline. The mechanic job has three levels, and there is a separate table containing data for the mechanics at each level: Certadv.Mechanicslevel1, Certadv.Mechanicslevel2, and Certadv.Mechanicslevel3. These tables all contain the same three columns.
The following PROC SQL step uses two OUTER UNION operators to concatenate the tables and the keyword CORR to overlay the columns that have common names:
proc sql;
   select *
      from certadv.mechanicslevel1 outer union corr
   select *
      from certadv.mechanicslevel2 outer union corr
   select *
      from certadv.mechanicslevel3;
quit;
Output 4.25 PROC SQL Query Result: Using OUTER UNION Operator and Keyword CORR (partial output)
Partial Result: PROC SQL Query Result: Using OUTER UNION Operator and Keyword CORR
Last updated: October 16, 2019
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.235.227