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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
  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

6 REPLIES 6
Reeza
Super User
  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.


 

VictorSirianni
Fluorite | Level 6

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;
ballardw
Super User

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.

VictorSirianni
Fluorite | Level 6

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?

Reeza
Super User

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. 

ballardw
Super User

@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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 5450 views
  • 4 likes
  • 3 in conversation