The SAS Output Delivery System and reporting techniques

Creating a proc template macro

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 133
Accepted Solution

Creating a proc template macro

Hi SAS Experts,

I wrapped my style and template code in a macro and thought I can call the macro instead of having this styling code in my programs.

First I have the proc sql to create a data set.

proc sql;

...

quit;

I then call the macro

%sas_report_style;

I add some program/report specifics to for the tagset:

ods tagsets.excelxp_mod file='C:\temp\NRKP_Soll_Haben.xml' style=styles.mycssstylescreen

options(

        embedded_titles='yes'

        Embedded_Footnotes = 'yes'

        Orientation = 'landscape'

        FitToPage = 'yes'

        Frozen_Headers = '7'

        Autofit_Height ='yes'

        Absolute_Column_Width='10,10,10,12,14,6,7,7,7,6,6,6,6,6'

        );

proc report data=xxx_xxxx;

run;

ods _all_ close;

The macro %sas_report_style looks like that:

%macro sas_report_style;

proc template;

/*HTML Style*/

define style styles.bvl_css_stylescreen;

    import "R:\style_v01.css" screen;

end;

run;

/***********************************************************/

/* Compile tagset Tagsets.ExcelXP_mod, which makes changes */

/* to the ExcelXP tagset to preserve the grid lines.       */

/***********************************************************/

proc template;

   define tagset tagsets.excelxp_mod;

      parent=tagsets.excelxp;

      define event sub_body;

         break /if $sub_body;

            set $sub_body "True";

            set $body_class "_body";

            put '<Style ss:ID="_body">' nl;

            put ' <Font ss:FontName="Arial, Helvetica, sans-serif" ssSmiley Frustratedize="10" ss:Color="#003399" />' NL;

            put "<Interior />" Nl;

            put '</Style>' nl;

            set $contents_class "_contents";

            put '<Style ss:ID="_contents">' nl;

            put ' <Interior ssSmiley Tongueattern="Solid" />' nl;

            put ' <Protection ssSmiley Tonguerotected="1" />' nl;

            put '</Style>' nl;

            set $pages_class "_pages";

            put '<Style ss:ID="_pages">' nl;

            put ' <Interior ssSmiley Tongueattern="Solid" />' nl;

            put ' <Protection ssSmiley Tonguerotected="1" />' nl;

            put '</Style>' nl;

      end;

   end;

run;

/* Remove table borders */

proc template;

   define style styles.test;

      parent=styles.minimal;

      style table from table /

            cellspacing=0

            borderwidth=0;

   end;

run;

%mend sas_report_style;

I get the error

ERROR 180-322: Statement is not valid or it is used out of proper order.

and I wonder why...is what I am doing feasible?


Accepted Solutions
Solution
‎08-14-2015 05:08 AM
Esteemed Advisor
Esteemed Advisor
Posts: 7,265

Re: Creating a proc template macro

Well, as for the tagset definitions, I am yet to find any decent help on them, so can't comment on your code.  I would however ask why you need to put template code in a macro?  It doesn't make any sense.  The point about templates is that once run, the ouput file is then used over various programs.  There is no reason to re-create it each time you run a program.  So create a templates folder somewhere and link to that via autoexec.sas.

For you second point, what are you trying to change in the tagsets.excelxp?  Is this the correct syntax for Excel to understand.  To be honest, I don't see that your going to be able to control that output that way unless you have a good understanding of the XML required, and how to write tagsets, I know the XML and personally wouldn't want to try it myself.  Normally there are better routes anyways.  For instance the tagset can get nice outputs - and that is all Excel is - so what do you need in addition?  If its something Excel specific then export your data to CSV, then write an Excel macro to import and process that data.  If necessary you can set all the formatting, graphs etc. up in that Excel file, then import and update from the CSV.  You then get simple SAS processing, and the full functionality of Excel.

Finally, you mention an ERROR, but do not show the log - with options mlogic mprint symbolgen enabled - so can't see what this applies to.

View solution in original post


All Replies
Solution
‎08-14-2015 05:08 AM
Esteemed Advisor
Esteemed Advisor
Posts: 7,265

Re: Creating a proc template macro

Well, as for the tagset definitions, I am yet to find any decent help on them, so can't comment on your code.  I would however ask why you need to put template code in a macro?  It doesn't make any sense.  The point about templates is that once run, the ouput file is then used over various programs.  There is no reason to re-create it each time you run a program.  So create a templates folder somewhere and link to that via autoexec.sas.

For you second point, what are you trying to change in the tagsets.excelxp?  Is this the correct syntax for Excel to understand.  To be honest, I don't see that your going to be able to control that output that way unless you have a good understanding of the XML required, and how to write tagsets, I know the XML and personally wouldn't want to try it myself.  Normally there are better routes anyways.  For instance the tagset can get nice outputs - and that is all Excel is - so what do you need in addition?  If its something Excel specific then export your data to CSV, then write an Excel macro to import and process that data.  If necessary you can set all the formatting, graphs etc. up in that Excel file, then import and update from the CSV.  You then get simple SAS processing, and the full functionality of Excel.

Finally, you mention an ERROR, but do not show the log - with options mlogic mprint symbolgen enabled - so can't see what this applies to.

Frequent Contributor
Posts: 133

Re: Creating a proc template macro

Hi RW9.

Thanks for the hint with the autoexec, I didnt realize I can reference the template in the autoexec.sas

That is a good idea.

I have no problem with the custom tagset. It works fine. All the custom tagset does

is to preserve the grid lines. Found that somewhere on the internet and it works.

☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 483 views
  • 0 likes
  • 2 in conversation