BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
zhangda
Fluorite | Level 6

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

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;

        

 

View solution in original post

1 REPLY 1
Shmuel
Garnet | Level 18

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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1350 views
  • 0 likes
  • 2 in conversation