Edit

SAS: PROC SQL (Cross Join for CARTESIAN PRODUCT)

2017/01/19
  In mathematics, a cartesian product is a mathematical operation that returns a set (or product set or simply product) from multiple sets. That is, for sets A and B, the Cartesian product A × B is the set of all ordered pairs (a, b) where a ∈ A and b ∈ B (Wikipedia).

  This is the all combinations of multiple variables.  In SQL procedure, there are two approach which are 'CROSS JOIN' and 'Just describing two tables with comma.'  It is useful concept as a tips of a  practical programming skillThis concept was referred from THIS ARTICLE on 'SAS 備忘録 (Japanese Blog).' 


PROGRAM 
--------------------------------------

DATA ID ;
 DO ID=1 TO 3 ;
  OUTPUT;
 END ;
RUN ;

DATA WEEK ;
 DO WEEK=1 TO 10 BY 2 ;
   OUTPUT ;
 END ;
RUN ;

***********************************************************
METHOD 1
***********************************************************;
PROC SQL ;
 CREATE TABLE DATA AS
  SELECT ID, WEEK
  FROM ID, WEEK
;
QUIT ;

***********************************************************
METHOD 2
***********************************************************;
PROC SQL ;
 CREATE TABLE DATA AS
  SELECT ID, WEEK
  FROM ID CROSS JOIN WEEK
;
QUIT ;

PROC PRINT; RUN;

--------------------------------------  


OUTPUT (Three ID includes all week )

















-------------------------------------- 
Reference: SAS 備忘録
 
Updated on Jan 19, 2017.

Search This Blog