Help using Base SAS procedures

How to macro the code?

Accepted Solution Solved
Reply
Contributor
Posts: 74
Accepted Solution

How to macro the code?

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;


Accepted Solutions
Solution
‎09-02-2016 03:02 PM
Trusted Advisor
Posts: 1,574

Re: How to macro the code?

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


All Replies
Solution
‎09-02-2016 03:02 PM
Trusted Advisor
Posts: 1,574

Re: How to macro the code?

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;

        

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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