Identifying Subjects with “n” Observations Each (Using PROC FREQ)

You can use PROC FREQ to count the number of observations per subject, just as you did to detect duplicates. Use the variable COUNT to determine the number of observations for each value of PATNO, as shown in Program 5-12.

Program 5-12. Using PROC FREQ to List All ID’s for Patients Who Do Not Have Exactly Two Observations
PROC FREQ DATA=CLEAN.PATIENTS2 NOPRINT;
   TABLES PATNO / OUT=DUP_NO(KEEP=PATNO COUNT
                             WHERE=(COUNT NE 2));
RUN;


DATA _NULL_;
   TITLE "Patient ID's for Patients with Other than Two Observations";
   FILE PRINT;
   SET DUP_NO;
   PUT "Patient number " PATNO "has " COUNT "observation(s).";
RUN;

The output data set from PROC FREQ (DUP_NO) contains the variables PATNO and the ...

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.