Build reports by using ODS to create HTML, PDF, RTF, Excel, text reports and more!

Using Macro Variables in ODS Text or PROC ODSTEXT

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

Using Macro Variables in ODS Text or PROC ODSTEXT

[ Edited ]

Hello,

 

I am trying to print page titles on an ODS PDF using ODS Text or PROC ODSTEXT. I would like to include several macro variables as the program runs through a loop generating reports for multiple employees. I am using Enterprise Guide 7.13 running SAS 9.4 in a Grid environment.

 

Using ODS TEXT the macro variables resolve correctly, however, the style formatting is not applied and the results include the style code:

/* title */
  ods text = "^S={font_size = 11pt font_weight = bold just = center} Month End Performance Scorecard";
  ods text = "^S={font_size = 10pt just = center} [placeholder] | &word_date. | &name.";

  

Output on PDF

^S={font_size = 11pt font_weight = bold just = center} Month End Performance Scorecard

^S={font_size = 10pt just = center} [placeholder] | Feb 2018 | Lastname, Firstname

 

Using PROC ODS TEXT the formatting is applied correctly, however, I have been able to figure out how to pass through the macro variables using PROC TEMPLATE and an MVAR statement or any other technique:

proc odstext;
  p 'Month End Performance Scorecard' / style = {font_size = 11pt font_weight = bold just = center};
  p '[placeholder] | ' || word_date || ' | ' || name / style = {font_size = 10pt just = center};
run;

No output is generated as this only results in errors.

 

 

Any help would be greatly appreciated.


Accepted Solutions
Solution
‎03-28-2018 11:26 AM
Super User
Posts: 24,028

Re: Using Macro Variables in ODS Text or PROC ODSTEXT

Posted in reply to VictorSirianni
  1. Macro variables only resolve with double quotes 
  2. You need a & in front of the macro variable which you forgot in the second example.

@VictorSirianni wrote:

Hello,

 

I am trying to print page titles on an ODS PDF using ODS Text or PROC ODSTEXT. I would like to include several macro variables as the program runs through a loop generating reports for multiple employees. I am using Enterprise Guide 7.13 running SAS 9.4 in a Grid environment.

 

Using ODS TEXT the macro variables resolve correctly, however, the style formatting is not applied and the results include the style code:

/* title */
  ods text = "^S={font_size = 11pt font_weight = bold just = center} Month End Performance Scorecard";
  ods text = "^S={font_size = 10pt just = center} [placeholder] | &word_date. | &name.";

  

Output on PDF

^S={font_size = 11pt font_weight = bold just = center} Month End Performance Scorecard

^S={font_size = 10pt just = center} [placeholder] | Feb 2018 | Lastname, Firstname

 

Using PROC ODS TEXT the formatting is applied correctly, however, I have been able to figure out how to pass through the macro variables using PROC TEMPLATE and an MVAR statement or any other technique:

proc odstext;
  p 'Month End Performance Scorecard' / style = {font_size = 11pt font_weight = bold just = center};
  p '[placeholder] | ' || word_date || ' | ' || name / style = {font_size = 10pt just = center};
run;

No output is generated as this only results in errors.

 

 

Any help would be greatly appreciated.


 

View solution in original post


All Replies
Solution
‎03-28-2018 11:26 AM
Super User
Posts: 24,028

Re: Using Macro Variables in ODS Text or PROC ODSTEXT

Posted in reply to VictorSirianni
  1. Macro variables only resolve with double quotes 
  2. You need a & in front of the macro variable which you forgot in the second example.

@VictorSirianni wrote:

Hello,

 

I am trying to print page titles on an ODS PDF using ODS Text or PROC ODSTEXT. I would like to include several macro variables as the program runs through a loop generating reports for multiple employees. I am using Enterprise Guide 7.13 running SAS 9.4 in a Grid environment.

 

Using ODS TEXT the macro variables resolve correctly, however, the style formatting is not applied and the results include the style code:

/* title */
  ods text = "^S={font_size = 11pt font_weight = bold just = center} Month End Performance Scorecard";
  ods text = "^S={font_size = 10pt just = center} [placeholder] | &word_date. | &name.";

  

Output on PDF

^S={font_size = 11pt font_weight = bold just = center} Month End Performance Scorecard

^S={font_size = 10pt just = center} [placeholder] | Feb 2018 | Lastname, Firstname

 

Using PROC ODS TEXT the formatting is applied correctly, however, I have been able to figure out how to pass through the macro variables using PROC TEMPLATE and an MVAR statement or any other technique:

proc odstext;
  p 'Month End Performance Scorecard' / style = {font_size = 11pt font_weight = bold just = center};
  p '[placeholder] | ' || word_date || ' | ' || name / style = {font_size = 10pt just = center};
run;

No output is generated as this only results in errors.

 

 

Any help would be greatly appreciated.


 

Occasional Contributor
Posts: 9

Re: Using Macro Variables in ODS Text or PROC ODSTEXT

Thank you @Reeza, I must have missed a typo and then spiraled off down the rabbit hole of far more complicated solutions. Always double check the basics I suppose. For anyone else who stumbles across this the revised code which now works is as follows:

 

proc odstext;
  p "Month End Performance Scorecard" / style = {font_size = 11pt font_weight = bold just = center};
  p "%trim(&role.)  |  %trim(&word_date.)  |  &name." / style = {font_size = 10pt just = center};
run;
Super User
Posts: 13,950

Re: Using Macro Variables in ODS Text or PROC ODSTEXT

Posted in reply to VictorSirianni

For completeness sake: did you  use an ODS ESCAPECHAR='^'; statement prior to the ODS Text cod?

 

I think that you MAY want FONTSIZE and FONTWEIGHT as well.

Occasional Contributor
Posts: 9

Re: Using Macro Variables in ODS Text or PROC ODSTEXT

Thank you @ballardw, adding the ODS ESCAPECAHAR also worked, two solutions for one problem! Since both ODS TEXT and PROC ODSTEXT are now working, is there any particular reason to use one over the other?

 

Also, I've seen some examples using font style elements with an underscore and some without (i.e. font_size and fontsize). The underscored versions seem to be working for me, but again, is there any particular reason to use one over the other?

Super User
Posts: 24,028

Re: Using Macro Variables in ODS Text or PROC ODSTEXT

Posted in reply to VictorSirianni

I think PROC ODSTEXT is easier to navigate and modify from a programming perspective. I *think* but can't test at the moment, but it also has some differences on when it's written to the document. ODS TEXT is only executed once it hits the next step and PROC ODSTEXT will run either way. 

Super User
Posts: 13,950

Re: Using Macro Variables in ODS Text or PROC ODSTEXT

Posted in reply to VictorSirianni

@VictorSirianni wrote:

Thank you @ballardw, adding the ODS ESCAPECAHAR also worked, two solutions for one problem! Since both ODS TEXT and PROC ODSTEXT are now working, is there any particular reason to use one over the other?

 


This can depend quite a bit on your destination and active style. By default ODS TEXT results tend to get treated as table entries and appear in the result with the background and border characteristics of table header text, which may or not be desirable. The behavior can be overridden in some ODS destinations but the syntax changes somewhat between the destinations. Proc ODSTEXT seems to be a bit less obnoxious about the border/background issues.

 

Having made bulleted lists with ods text before Procs ODSTEXT or ODSLIST were available. If your desired text involves bulleted lists or similar output I would say that the Procs win hands down. Also the ability to use dataset input to provide variables as Proc ODSTEXT allows would have saved me a lot of headaches with getting ODS TEXT to create those lists. Such things as the TRANSLATE INTO to modify displayed text based on values or ranges of values are also of interest and coupled with cellstyle options based on  values of multiple variable can make certain forms of highlighting of output much more flexible than cell-content based highlighting.

 

ODS TEXT may be more flexible if you want to modify the appearance of one or two words in a small amount of text and reset back for the remainder of the text.

 


 

Also, I've seen some examples using font style elements with an underscore and some without (i.e. font_size and fontsize). The underscored versions seem to be working for me, but again, is there any particular reason to use one over the other?


Some of the ODS style elements were first done with one name, such as font_size, earlier in development have been replaced in documentation with fontsize. SAS still recognizes the older form as a valid alias but you never know when the alias may quit working. In ODS related issues I try to keep up with the current options/elements/ or however you want to think of these things so that I don't have to make internal adjustments when reading program examples.

☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 370 views
  • 2 likes
  • 3 in conversation