Hello, can you tell me how to macro the following code, two parts, first, the dataset, I have to report dozens of same datasets, and add ods pdf startpage=no to separate them, second, the variables, you can see the 'compute year2016' part, I have to repeat 5 times for each dataset, would you please help me to simplify the code? thank you so much!
Proc report data=final contents=" " nowd split='\'
style(report)={font_size=14pt cellpadding=4pt cellspacing=1 rules=none frame=void}
style(header)={color=white background=cornflowerblue fontsize=14pt}
style(column)={just=center background=snow foreground=black fontsize=13pt};
column _name_ year2016 year2015 Num_of_Variance mature2015 Num_of_Variance2 ;
define _name_ / "Metrics" style=[foreground=negfmt.];
define year2016/ "&Mar_Yr." style=[foreground=negfmt.];
define year2015/ " &Mar_PreYr." style=[foreground=negfmt.];
define Num_of_Variance/ "#Variance" style=[foreground=negfmt.];
define mature2015/ "Mature &Mar_PreYr." style=[foreground=negfmt.];
define Num_of_Variance2/ "#Variance" style=[foreground=negfmt.];
compute _name_ ;
if _name_= 'Avg FICO' then call define(_row_,'style','style={background=gainsboro}');
if _name_= 'Avg Approve FICO' then call define(_row_,'style','style={background=gainsboro}');
endcomp;
compute year2016 ;
If _name_='Application' then call define(_col_,'format','comma20.0');
If _name_='CreditAR' then call define(_col_,'format','percent8.1');
if _name_= 'JudgmentalAR' then call define(_col_,'format','percent8.1');
if _name_= 'Referral % ' then call define(_col_,'format','percent8.1');
endcomp;
compute year2015 ;
If _name_='Application' then call define(_col_,'format','comma20.0');
If _name_='CreditAR' then call define(_col_,'format','percent8.1');
if _name_= 'JudgmentalAR' then call define(_col_,'format','percent8.1');
if _name_= 'Referral % ' then call define(_col_,'format','percent8.1');
endcomp;
compute Num_of_Variance ;
If _name_='Application' then call define(_col_,'format','comma20.0');
If _name_='CreditAR' then call define(_col_,'format','percent8.1');
if _name_= 'JudgmentalAR' then call define(_col_,'format','percent8.1');
if _name_= 'Referral % ' then call define(_col_,'format','percent8.1');
endcomp;
compute mature2015 ;
If _name_='Application' then call define(_col_,'format','comma20.0');
If _name_='CreditAR' then call define(_col_,'format','percent8.1');
if _name_= 'JudgmentalAR' then call define(_col_,'format','percent8.1');
if _name_= 'Referral % ' then call define(_col_,'format','percent8.1');
endcomp;
compute Num_of_Variance2 ;
If _name_='Application' then call define(_col_,'format','comma20.0');
If _name_='CreditAR' then call define(_col_,'format','percent8.1');
if _name_= 'JudgmentalAR' then call define(_col_,'format','percent8.1');
if _name_= 'Referral % ' then call define(_col_,'format','percent8.1');
endcomp;
run;
ods pdf startpage=no;
Proc report data=final_ytd contents=" " nowd split='\'
style(report)={font_size=14pt cellpadding=4pt cellspacing=1 rules=none frame=void}
style(header)={color=white background=cornflowerblue fontsize=14pt}
style(column)={just=center background=snow foreground=black fontsize=13pt};
column _name_ year2016 year2015 Num_of_Variance mature2015 Num_of_Variance2 ;
define _name_ / "Metrics" style=[foreground=negfmt.];
define year2016/ "YTD&Yr." style=[foreground=negfmt.];
define year2015/ " YTD&PreYr." style=[foreground=negfmt.];
define Num_of_Variance/ "#Variance" style=[foreground=negfmt.];
define mature2015/ "Mature YTD&PreYr." style=[foreground=negfmt.];
define Num_of_Variance2/ "#Variance" style=[foreground=negfmt.];
compute _name_ ;
if _name_= 'Avg FICO' then call define(_row_,'style','style={background=gainsboro}');
if _name_= 'Avg Approve FICO' then call define(_row_,'style','style={background=gainsboro}');
endcomp;
compute year2016 ;
If _name_='Application' then call define(_col_,'format','comma20.0');
If _name_='CreditAR' then call define(_col_,'format','percent8.1');
if _name_= 'JudgmentalAR' then call define(_col_,'format','percent8.1');
if _name_= 'Referral % ' then call define(_col_,'format','percent8.1');
endcomp;
compute year2015 ;
If _name_='Application' then call define(_col_,'format','comma20.0');
If _name_='CreditAR' then call define(_col_,'format','percent8.1');
if _name_= 'JudgmentalAR' then call define(_col_,'format','percent8.1');
if _name_= 'Referral % ' then call define(_col_,'format','percent8.1');
endcomp;
compute Num_of_Variance ;
If _name_='Application' then call define(_col_,'format','comma20.0');
If _name_='CreditAR' then call define(_col_,'format','percent8.1');
if _name_= 'JudgmentalAR' then call define(_col_,'format','percent8.1');
if _name_= 'Referral % ' then call define(_col_,'format','percent8.1');
endcomp;
compute mature2015 ;
If _name_='Application' then call define(_col_,'format','comma20.0');
If _name_='CreditAR' then call define(_col_,'format','percent8.1');
if _name_= 'JudgmentalAR' then call define(_col_,'format','percent8.1');
if _name_= 'Referral % ' then call define(_col_,'format','percent8.1');
endcomp;
compute Num_of_Variance2 ;
If _name_='Application' then call define(_col_,'format','comma20.0');
If _name_='CreditAR' then call define(_col_,'format','percent8.1');
if _name_= 'JudgmentalAR' then call define(_col_,'format','percent8.1');
if _name_= 'Referral % ' then call define(_col_,'format','percent8.1');
endcomp;
run;
As much as I see you are repeating same lines few times except the COMPUTE argument.
you can define:
%macro comp(arg);
compute &arg;
If _name_='Application' then call define(_col_,'format','comma20.0');
If _name_='CreditAR' then call define(_col_,'format','percent8.1');
if _name_= 'JudgmentalAR' then call define(_col_,'format','percent8.1');
if _name_= 'Referral % ' then call define(_col_,'format','percent8.1');
endcomp;
%mend common_lines;
Then change your code to:
Proc report data=final contents=" " nowd split='\'
.... enter your code here upto ...
%comp(year2015);
%comp(year2016);
%comp( Num_of_Variance);
%comp(mature2015);
%comp( Num_of_Variance2);
RUN;
As much as I see you are repeating same lines few times except the COMPUTE argument.
you can define:
%macro comp(arg);
compute &arg;
If _name_='Application' then call define(_col_,'format','comma20.0');
If _name_='CreditAR' then call define(_col_,'format','percent8.1');
if _name_= 'JudgmentalAR' then call define(_col_,'format','percent8.1');
if _name_= 'Referral % ' then call define(_col_,'format','percent8.1');
endcomp;
%mend common_lines;
Then change your code to:
Proc report data=final contents=" " nowd split='\'
.... enter your code here upto ...
%comp(year2015);
%comp(year2016);
%comp( Num_of_Variance);
%comp(mature2015);
%comp( Num_of_Variance2);
RUN;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.