Edit

SAS: PROC SQL (Having)

  This is the article for 'Having clause' to extract the results after summarizing.  In this example, 'more than 12 of mean of RES variable' was extracted into the table.  The difference between 'Having' and 'Where' is when the results will be extracted.  The 'Having' is 'after summarizing data,' and 'Where' is 'before summarizing data' as this Japanese BLOG mentioned.


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

DATA SAMPLE ;
INPUT CAT RES ;
CARDS ;
1 10
1  9
1  9
1  8
1 10
2 20
2 21
2 21
2 20
2 20
;
RUN ;

*****************************************************
EXTRACTING SOME SUMMARIZED DATA TO USE HAVING CLAUSE
*****************************************************;
PROC SQL ;
 CREATE TABLE D4
 AS SELECT CAT, MEAN(RES) AS RES_MEAN
 FROM SAMPLE
 GROUP BY CAT
 HAVING MEAN(RES)>12 /*NOT USE 'RES_MEAN'.  ONLY SHOW MEAN > 12.*/
;
QUIT ;

PROC PRINT; RUN ;
-------------------------------------  

OUTPUT (ONLY when CAT=2)


Search This Blog