Sample 25268: Interleaving SAS tables using PROC SQL
This example uses PROC SQL and the "Outer Union Corr" Set Operator to concatenate the two SAS tables within an "Inline View." The CORR keyword aligns the columns by corresponding column names.
The ORDER BY clause orders the results by the column ID, producing
the interleaved results.
Any columns which do not have corresponding columns are retained in the result set.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
data one;
input ID var1 var2;
cards;
1 2 3
4 5 6
20 2 2
7 8 9
;
data two;
input ID var1 var2;
cards;
10 20 30
40 50 60
5 5 5
70 80 90
;
proc sql;
create table final as
select * from
(select * from one
outer union corr
select * from two)
order by id;
quit;
proc print data=final;
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Obs ID var1 var2
1 1 2 3
2 4 5 6
3 5 5 5
4 7 8 9
5 10 20 30
6 20 2 2
7 40 50 60
8 70 80 90
This example illustrates using PROC SQL with the Set Operator OUTER UNION to interleave two SAS tables.
| Type: | Sample |
| Topic: | SAS Reference ==> Procedures ==> SQL
|
| Date Modified: | 2005-03-19 03:02:42 |
| Date Created: | 2005-03-16 13:52:56 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |