Dear community,
Is it possible to directly put word field codes in titles, footnotes, proc report posttext and line statements, etc? According to https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2019/3235-2019.pdf, this is possible with proc template, but this would just modify existing template elements.
What I am trying to achieve is to hand over table numbering to Word for easy list-of-tables creation. According to google, the field code for table number is {SEQ Table \* ARABIC}. Unfortunately, if I use it as-is, the literal is inserted to document, and prepending it with an ods escapechar (~{SEQ Table \* ARABIC}) results in nothing being inserted. Thank you.
Since the ODS Word is either pre-production or new depending on the exact version of SAS running you need to make sure that you let people know exactly which SAS release you are working with.
Run this code snippet:
%put SAS Version: &sysvlong.;
The Log will show something like:
SAS Version: 9.04.01M4P110916
Copy your result from the Log and paste it in your response.
Second you should show an example of the code you are attempting with the ODS WORD destination and some example output. Best would be to use SAS supplied data sets from the SASHELP library like the Sashelp.class data set so we can test code and be pretty sure that the data content is not involved.
Please paste the code into a code box opened on the forum with either the </> or "running man" icon so we can tell where the code starts and ends and maintain formatting. The forum will reformat code and sometimes inserts html codes into code pasted into the main window that makes code run incorrectly when copied.
My SAS Version is 9.04.01M7P080520. THe code I was testing with came from https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2019/3235-2019.pdf:
ods path (prepend) work.templat(update);
proc template;
define style styles.mystyle;
parent = styles.word;
class pageno /
content = "This works: Page {PAGE} of {NUMPAGES}, this sort of: Table {SEQ Table \* ARABIC }"
just = c
vjust = b
;
end;
run;
ods word file="c:\users\&sysuserid\Work Folders\Desktop\test.docx"
options(keep_next="on") style=mystyle;
title "This doesn't: Page {PAGE} of {NUMPAGES} Table {SEQ Table \* ARABIC }";
proc print data=sashelp.cars;
where Origin="USA";
run;
ods word close;
The table field code from the template does not work because it is not meant for headers or footers, if it is copied to the document body in Word it works fine. I thought falling back to RTF might be an option, considering this:
https://www.lexjansen.com/nesug/nesug08/bb/bb03.pdf
Unfortunately, this code does not work either:
ods rtf file="c:\users\&sysuserid\Work Folders\Desktop\test.rtf";
title "Table \field{\*\fldinst{SEQ Table \\* ARABIC }}: Text for your title}";
proc print data=sashelp.cars;
where Origin="USA";
run;
ods rtf close;
The title text gets inserted verbatim.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.