Edit

SAS: PROC SQL (Group By)

2016/12/18
  This article is to show a sample program for 'Group By' clause which is to summarize a variable by defined variable (s).  Basically, this is similar to 'PROC Mean' procedure or 'PROC Summary' procedure.  However, one big difference that I feel it is very useful is 'DISTINCT' option.  This can be counted only once for a variable with duplicated data.  For example, even if a table includes multiple efficacy data over time by a subject, you can count 'the number of subjects' in a same procedure. 


PROGRAM 
--------------------------------------
******************************************************************
GROUP BY: SUMMARY BY CATEGORY
------------------------------------------------------------------
Other summary functions available are
the AVG/MEAN,
    STD, VAR

    MAX, MIN, 
    COUNT/FREQ/N, 
    NMISS,     SUM.
This capability Is similar to PROC SUMMARY/MEANS 
with a CLASS statement.
******************************************************************;
PROC SQL ;
 CREATE TABLE EFFICACY1 AS
 SELECT DOSE,
        VISIT2,
        COUNT(DISTINCT (SUBJECT)) AS N,
        MEAN(RES)                 AS MEAN   FORMAT 10.1,
        STD (RES)                 AS SD     FORMAT 10.2,
        MIN (RES)                 AS MIN    FORMAT 10.1,
        MEDIAN (RES)              AS MEDIAN FORMAT 10.1,
        MAX (RES)                 AS MAX    FORMAT 10.1
 FROM EFFICACY
 GROUP BY DOSE, VISIT2 ;
QUIT ; 

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



OUTPUT (NOT FULL DATA)


Search This Blog