Sample Data (Program and Results)
Two sample source data for 'UNION' clause, DEMOG1 and DEMOG2.
--------------------------------------
/* The source table was read from LINK*/
DATA DEMOG1 ;
SET DEMOG ;
WHERE DOSE=1 ;
KEEP SUBJECT AGE ; /*--PICK UP AGE--*/
RUN ;
--------------------------------------
/*--------------------------------------------------
SQL Sample Program and the Results (UNION CORR)
/*------------------------
NOTE: If we removed 'ALL' prior to 'UNION' or 'UNION CORRESPONDING,' then duplicated record will be removed from a created table.
/* The source table was read from LINK*/
DATA DEMOG1 ;
SET DEMOG ;
WHERE DOSE=1 ;
KEEP SUBJECT AGE ; /*--PICK UP AGE--*/
RUN ;
--------------------------------------
SQL Sample Program and the Results (UNION Only)
The following example is 'UNION' clause with no option. The 'UNION' clause sets two tables based on order regardless of variable name. In the following example, DEMOG1 has SUBJECT and AGE, and DEMOG2 has SUBJECT and WT. The SUBJECT is common for two tables, but AGE and WT are different variable for these two tables. However, this 'UNION' clause sets these two variables because these two are second variable in each table.
/*--------------------------------------------------
* UNION ONLY *
* SET THE VARIABLES BY ORDER
REGARDLESS OF VARIABLE *
* 1ST: SUBJECT (PICK UP
COMMON), *
* 2ND: AGE AND WT. *
*---------------------------------------------------*/
PROC SQL ;
CREATE TABLE DEMOG3 AS
SELECT * FROM DEMOG1
UNION ALL
SELECT * FROM DEMOG2
;
QUIT ;
SQL Sample Program and the Results (UNION CORR)
The following example is 'UNION CORRESPONDING' clause. This clause extract only common variables for both tables. In this example, common variable is SUBJECT only, and AGE in DEMOG1 and WT in DEMOG2 will be removed from created table.
/*------------------------
* UNION CORRESPONDING *
* KEEP COMMON VARIABLES *
*------------------------*/
PROC SQL ;
CREATE TABLE DEMOG3 AS
SELECT * FROM DEMOG1
UNION CORRESPONDING ALL
SELECT * FROM DEMOG2
;
QUIT ;
NOTE: If we removed 'ALL' prior to 'UNION' or 'UNION CORRESPONDING,' then duplicated record will be removed from a created table.
REFERENCE
- SAS 備忘録
Post a Comment
別ページに移動します