Monday, January 30, 2012

Proc SQL And UNION

There are five Union operators in Proc SQL. Four perform very different operations than the simple concatenation seen here – and several of those are very difficult to code in the SAS Data Step.

Union - matches by column position, not name, and drops duplicate rows

Union All - matches by column position, not name, and doesn’t drop duplicate rows

Union Corresponding - matches by column name and drops duplicate rows

Except - matches by column name and drops the rows found in both tables

Intersection - matches by column name and keeps the unique rows in both tables

The Unions can be combined also. Two tables could be concatenated with a Union Corresponding and then that result intersected with another table to find the records in the last table that were also in either the first table or the second.

No comments:

Post a Comment