BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
acordes
Rhodochrosite | Level 12

I would like to replace the hard-coded text in my code. A file in txt format should fill-in the text. 

I'm looking for a an %include statement.

 

Is this possible?

I've found a reference which lools promising. But I can't get it work. 

https://support.sas.com/resources/papers/proceedings09/222-2009.pdf  

 

ods escapechar='^';
proc odstext;
p '01. ^{style[textdecoration=underline fontsize=14pt]Problem statement:} ^{newline 1} ^{style[color=blue ]Maintenance contracts have a significant share in the 
portfolio of VWFS. During their lifetime they cause expenses to VWFS. Their cost pattern depends on many factors making it difficult to measure and compare. 
As the pricing is furthermore subject to numerous specific contract and vehicle criteria, the interpretation of the economic result becomes even more complex.  
}  ^{newline 2}';

p '02. ^{style[textdecoration=underline fontsize=14pt]What was done and how:} ^{newline 1} ^{style[color=blue ]We accumulated all costs and incomes (through monthly rate) for any given 
contract in the Portfolio during its lifetime. These events were expanded to a timeseries so that a contracts result can be assessed at any point of time, real=past and 
estimated=future. Advanced algorithms estimate each variables contribution to the observed results thus making it possible to compare the result between subjects.  
}  ^{newline 2}';

run;
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
You read the txt file into a SAS data set, create a macro variable from that data set and then pipe that to your code. Probably the easiest dynamic solution IMO.

View solution in original post

8 REPLIES 8
Reeza
Super User
Is it a one to one replacement of the text to the p statement or do you need to add the formatting eg. Newline, style/text decoration?

If it's one to one replacement it's trivial. If it's the latter, that's more complicated.
acordes
Rhodochrosite | Level 12
No fancy things needed.
I'm just looking for the functional aspect. The one on one replacement as you say.
Reeza
Super User
Then yes, it's trivial to do just depends on exactly how the text data is structured.

You can read it in and store in macro variables that are referenced in the code and replace your string.
You could also dynamically generate the full code. You'd have to provide more details as to your usage for a full solution, for example if there were a variable quantity of bullets then you want to use the second option. If its always 2 then using macro variables is fine.

acordes
Rhodochrosite | Level 12
Okay.
To put you in the picture.
Today I've "discovered" proc odstext and odslist while seeking a code-driven solution to create an analytical report including data prep, modeling and visualization triggered by different procs.
They come in very handy for comments and overall project description. The latter is the part I'd like to outsource to the business owners.
They should provide a txt file with the "Context" description of the analytics project. I'd like to plug in this description in the P lines.
Okay, I can create a macro variable and use it. I thought there would exist an easier solution, more straightforward.
I started using ods word but I prefer ods pdf as it creates hyperlinks to the output objects.
Reeza
Super User
You read the txt file into a SAS data set, create a macro variable from that data set and then pipe that to your code. Probably the easiest dynamic solution IMO.

Cynthia_sas
SAS Super FREQ

Hi:
I suspect the reason the example in the paper didn't work is that the paper was written back in 2009 and I believe that the tagset templates have changed since the paper was written. I think that using a TAGSET template for this type of thing is too complicated an approach. As @Reeza suggests, using a macro variable is one way to do it and is also the first way I would approach a challenge like this.
Cynthia

PS...As an additional comment, I rarely would accept input from users without some heavy validation and checking first. So at the very least, unless you really really trust these users and are training them very well, I would have them place their additional comments in a file or location where you can find them and check them before you turn your process/program loose on input from end users.

acordes
Rhodochrosite | Level 12
Cynthia, can I add the pathname (like revealed by ods trace) as caption to an object created by a proc freq for example?
If this were possible, then I could easily create manually a table of figures in the ods word output...
Cynthia_sas
SAS Super FREQ

Hi:
Again, you'd probably have to use a macro variable. There is not a way to put the output object name into a caption using ODS TEXT automatically. You'd have to capture the name of the object, create a macro variable and then use the macro variable in the caption. But have you tried ODS PROCLABEL? The PROC label is the ODS way of typically using the self-announcing procedure title "The MEANS Procedure", "The TABULATE Procedure", etc in any table of contents. So if you used your macro variable in an ODS PROCLABEL you might not need ODS TEXT for your caption. Still using a macro variable, but possibly making it easier to generate your TOC with ODS WORD.
Cynthia

 

PS. I still get messages that ODS WORD is preproduction in the SAS 9.4M7 log, so my tendency would be to stick with ODS RTF if this is production work. Using either ODS WORD or ODS RTF, I can use ODS PROCLABEL to impact the TOC, as shown below:

Cynthia_sas_0-1673374762269.png

 

  I still have to manually do an "Update Field" to build the TOC when Word opens the created file. But now I'm sort of backpedaling on whether you'd really need a macro variable. Proc Means always creates MEANS.SUMMARY and most of the procedures have fixed paths, so while you could put the output object name in the caption, it might make more sense for you to use figure numbers and generally accepted descriptions for the Figures by hard-coding ODS PROCLABEL before each PROC step. I guess I'm still not clear on what you really need to generate, but I found a lot of good ODS WORD and TOC information in this paper: https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2020/4265-2020.pdf .

Cynthia

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
  • 8 replies
  • 829 views
  • 6 likes
  • 3 in conversation