%put _automatic_; /*using automatic macro variables */ proc print data=health.claims_sample; title 'Claims Report'; footnote "Created &systime, &sysday &sysdate9"; footnote2 "on the &sysscp system using &sysver"; run; /* creating and using user-defined macro variables */ /* begin with hardcoded values*/ proc print data=health.claims_sample; title "Report for 2006"; var providerID memberID chgamt lndiscamt eeresp paidamt; where svc_year="2006"; footnote; run; proc means data=health.claims_sample; title "Summary for 2006"; var chgamt lndiscamt eeresp paidamt; where svc_year="2006"; run; /* create user-defined macro variables */ %let year=2006; proc print data=health.claims_sample; var providerID memberID chgamt lndiscamt eeresp paidamt; title "Report for &year"; where svc_year="&year"; run; proc means data=health.claims_sample; title "Summary for &year"; var chgamt lndiscamt eeresp paidamt; where svc_year = "&year"; run; /*Reference Automatic Macro variable in title*/ proc print data=health.claims_sample; var providerID memberID chgamt lndiscamt eeresp paidamt; title "Report for &year"; title2 "current date and time is &sysdate &systime"; where svc_year="&year"; run; /*Use macro function to obtain current date and time */ proc print data=health.claims_sample; var providerID memberID chgamt lndiscamt eeresp paidamt; title "Report for &year"; title2 "current date and time is %sysfunc(today(),mmddyy8.) %sysfunc(time(), time.)"; where svc_year="&year"; run; /* create a macro program */ /* 2 steps - 1) compile or define the macro and then 2) call the macro */ %macro claiminfo; proc print data=health.claims_sample; var providerID memberID chgamt lndiscamt eeresp paidamt; title "Report for &year"; where svc_year="&year"; run; proc means data=health.claims_sample; title "Summary for &year"; var chgamt lndiscamt eeresp paidamt; where svc_year = "&year"; run; %mend; /* compile the macro with message regarding successful completion */ /* step 1: compile the macro */ options mcompilenote=all; %macro claiminfo; proc print data=health.claims_sample; var providerID memberID chgamt lndiscamt eeresp paidamt; title "Report for &year"; where svc_year="&year"; run; proc means data=health.claims_sample; title "Summary for &year"; var chgamt lndiscamt eeresp paidamt; where svc_year = "&year"; run; %mend; /* step 2: Call the macro*/ %let year=2006; %claiminfo /* use MPRINT to display the code generated by the macro program */ options mprint; %let year=2005; %claiminfo /* macro with parameters */ /* create the macro with a parameter (corresponds to the macro variable in the code */ %macro claiminfo(year); proc print data=health.claims_sample; var providerID memberID chgamt lndiscamt eeresp paidamt; title "Report for &year"; where svc_year="&year"; run; proc means data=health.claims_sample; title "Summary for &year"; var chgamt lndiscamt eeresp paidamt; where svc_year = "&year"; run; %mend; /* call the macro with a value for the parameter (Year) */ %claiminfo(2005) %claiminfo(2006) %claiminfo(2007) /* Use iterative processing to dynamically generate year values */ %macro claiminfo; %do year=2005 %to 2007; proc print data=health.claims_sample; var providerID memberID chgamt lndiscamt eeresp paidamt; title "Report for &year"; where svc_year="&year"; run; proc means data=health.claims_sample; title "Summary for &year"; var chgamt lndiscamt eeresp paidamt; where svc_year = "&year"; run; %end; %mend; options mlogic; %claiminfo %macro claiminfo(start, end); %do year=&start %to &end; proc print data=health.claims_sample; var providerID memberID chgamt lndiscamt eeresp paidamt; title "Report for &year"; where svc_year="&year"; run; proc means data=health.claims_sample; title "Summary for &year"; var chgamt lndiscamt eeresp paidamt; where svc_year = "&year"; run; %end; %mend; %claiminfo(2005,2007)