Finding Another Way to Determine Highest and Lowest Values

There is usually more than one way to solve any SAS problem. Here is another approach to listing the 10 highest and 10 lowest values for a variable in a SAS data set. The advantage of this program is that it always gives you exactly 10 high and 10 low values. The program is presented first, followed by a macro version of it.

Program 2-17. Listing the Highest and Lowest “n” Values Using PROC SORT
LIBNAME CLEAN "C:\CLEANING";
%LET VAR = HR;  ***Assign values to two macro variables;
%LET IDVAR = PATNO;


PROC SORT DATA=CLEAN.PATIENTS(KEEP=&IDVAR &VAR   1
                              WHERE=(&VAR NE .))
                              OUT=TMP;
   BY &VAR;
RUN;


DATA _NULL_;
   TITLE "Ten Highest and Ten Lowest Values for &VAR";
   SET TMP NOBS=NUM_OBS;   2 HIGH = NUM_OBS ...

Get Cody’s Data Cleaning Techniques Using SAS® Software now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.