Return to Homepage

Goto the Tip of the Month Archive

Other interesting pages ...
LinkedIn Profile
SAS Cheat Sheet
Useful SAS Code
Full SAS Example
Basic Statistics
Contact Information

SAS Tip of the Month
March 2014
(for SAS and WPS)

Occasionally we have to produce a set of listings for each subject, so if you have fifty subjects you have to produce fifty different sets of listings based on all the datasets. Here is one technique that works.

First, find the unique set of subjects being processed, usually from a list like a DEMOG list, using the following code:

   proc sql noprint;
      select distinct PATIENTID
         into: patlist separated by ' '
         from DEMOG;

The SQL has now created a unique set of subjects, which will be the list of subjects that we use to create the outputs.

Now lets get the program to produce the output:

   %macro prtmylst;
      %let i=1; *Use an internal counter;
      %do %while(%scan(&patlist,&i) ne ); *Go though the list and do an action until there is no more;

         proc printto print="C:\TUAI\PATLIST\%scan(&patlist,&i).LST";
            *Creates out output file, same name as PATIENTID value;

         *DEMOG and AE data, for this example, using PROC PRINT, but could easily be PROC REPORT;
         proc print data=demog noobs;
            where PATIENTID="%scan(&patlist,&i)";
         proc print data=ae noobs;
            where PATIENTID="%scan(&patlist,&i)";

         proc printto; *Close the existing destination;

         %let i=%eval(&i+1); *Get next subject on the list;

   %mend prtmylst;

As you can see this goes though the list and creates a set of PROC PRINT listings for each subject. This can be extended to use for PROC REPORT amound a number of different other procedures.

Hope this is useful. See you next month.

Updated March 2, 2014