Hi
I'm trying to create make a Macro Do Loop that will create individual reports like the one attached for the Proc Print procedure. But every time I run the code below, it just gets put into the log but no results are printed:
%macro patients;
%do i=1101 %to i=1109;
proc report data=Report3.Clinical3Sort nofs;
where PATIENT_ID=&i.;
title "Blood Pressure Med Study";
column PATIENT_ID DRUG SEX VISIT_DATE SYSTOLIC DIASTOLIC FEVER NAUSEA RASH;
define PATIENT_ID / group;
define DRUG / group;
define SEX / group;
define VISIT_DATE / display;
define SYSTOLIC / display;
define DIASTOLIC / display;
define FEVER / display;
define NAUSEA / display;
define RASH / display;
run;
%end;
%mend;
%patients;
Any help is appreciated
You don't need a macro for this - just a BY PATIENT_ID statement. If your dataset Report3.Clinical3Sort is already sorted by ID, you can just do this:
proc report data=Report3.Clinical3Sort nofs;
by PATIENT_ID;
where patient_id between 1101 and 1109;
title "Blood Pressure Med Study";
column PATIENT_ID DRUG SEX VISIT_DATE SYSTOLIC DIASTOLIC FEVER NAUSEA RASH;
define PATIENT_ID / group;
define DRUG / group;
define SEX / group;
define VISIT_DATE / display;
define SYSTOLIC / display;
define DIASTOLIC / display;
define FEVER / display;
define NAUSEA / display;
define RASH / display;
run;
And if the data aren't sorted by ID, just create a sorted dataset to submit to proc report:
proc sort data=Report3.Clinical3Sort out=temp;
where patient_id between 1101 and 1109;
by patient_id;
run;
proc report data=temp nofs;
by patient_id;
.......
run;
You don't need a macro for this - just a BY PATIENT_ID statement. If your dataset Report3.Clinical3Sort is already sorted by ID, you can just do this:
proc report data=Report3.Clinical3Sort nofs;
by PATIENT_ID;
where patient_id between 1101 and 1109;
title "Blood Pressure Med Study";
column PATIENT_ID DRUG SEX VISIT_DATE SYSTOLIC DIASTOLIC FEVER NAUSEA RASH;
define PATIENT_ID / group;
define DRUG / group;
define SEX / group;
define VISIT_DATE / display;
define SYSTOLIC / display;
define DIASTOLIC / display;
define FEVER / display;
define NAUSEA / display;
define RASH / display;
run;
And if the data aren't sorted by ID, just create a sorted dataset to submit to proc report:
proc sort data=Report3.Clinical3Sort out=temp;
where patient_id between 1101 and 1109;
by patient_id;
run;
proc report data=temp nofs;
by patient_id;
.......
run;
The log showing submitted lines but no results is a typical behavior after some of the common syntax errors when learning the macro language. Creating something with unbalanced quotes, parentheses, or improperly ended statements can place the system into an unsteady state.
You likely have to close the SAS session and restart.
I would suggest that until you get experience with the macro language that you always set OPTIONS MPRINT; before running any macro and then reading the log closely. Almost any warning is something to be investigated. Also with MPRINT on then any messages appear in better relation to the issue instead of a series of notes at the end of the macro execution.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.