*----------------------------------------------------------------* | Purpose: To list the upper and lower n% of values | | Arguments: DSN - Data set name (one- or two-level | | VAR - Variable to test | | PERCENT - Upper and lower n% | | IDVAR - ID variable | | Example: %HI_LOW_P(CLEAN.PATIENTS,SBP,20,PATNO) | *----------------------------------------------------------------*; %MACRO HI_LOW_P(DSN,VAR,PERCENT,IDVAR); ***Compute number of groups for PROC RANK; %LET GRP = %SYSEVALF(100 / &PERCENT,FLOOR); ***Value of the highest GROUP from PROC RANK, equal to the number of groups - 1; %LET TOP = %EVAL(&GRP - 1); PROC FORMAT; VALUE RNK 0='Low' &TOP='High'; RUN; PROC RANK DATA=&DSN OUT=NEW GROUPS=&GRP; VAR &VAR; RANKS RANGE; RUN; ***Sort and keep top and bottom n%; PROC SORT DATA=NEW (WHERE=(RANGE IN (0,&TOP))); BY &VAR; RUN; ***Produce the report; PROC PRINT DATA=NEW; TITLE "Upper and Lower &PERCENT.% Values for %UPCASE(&VAR)"; ID &IDVAR; VAR RANGE &VAR; FORMAT RANGE RNK.; RUN; PROC DATASETS LIBRARY=WORK NOLIST; DELETE NEW; RUN; QUIT; %MEND HI_LOW_P;