Hello,
I am trying to make a custom word template. I got most of the way there, but I can't change the font of the 1st TOC level to Arial:
proc template;
define style styles.customjournal;
parent = styles.journal1a;
style fonts from fonts /
'docFont' = ("Arial", 10pt)
'headingFont' = ("Arial", 10pt, bold)
'TitleFont' = ("Arial", 10pt, bold)
'FooterFont' = ("Arial", 9pt);
style Table from Table /
cellpadding = 2;
style Header from Header /
background=grayf2;
style Data from Data /
just=center;
style TitlesAndFooters from TitlesAndFooters /
just=left;
style SystemFooter from TitlesAndFooters /
font = Fonts('FooterFont');
style SystemTitle2 from SystemTitle /
font = Fonts('docFont');
style SystemTitle3 from SystemTitle;
class contenttitle /
content = "TABLE OF CONTENTS"
font = Fonts('TitleFont')
fontsize=5
just = left;
class TOC1 /
marginbottom = 5pt
font = Fonts('docFont');
class TOC2 /
marginleft = .14in
marginbottom = 5pt
font = Fonts('docFont');
class TOC3 /
marginleft = .28in
marginbottom = 5pt
font = Fonts('docFont');
end;
run;
options nobyline nodate nonumber;
options topmargin=2.5cm leftmargin=3.0cm bottommargin=1.5cm rightmargin=1.5cm;
options orientation=landscape;
options papersize="ISO A4";
ods word file="C:\Users\&sysuserid\Downloads\SAS\toc_issue.docx" style=styles.customjournal
options(cant_split="no"
toc_data="yes"
contents="yes");
proc report data=sashelp.cars;
columns Origin Make n;
define Origin / group;
define Make / group;
run;
ods word close;
options byline date number;
options orientation=portrait;
In Word, the font is Cumberland AMT which I assume is a leftover from journal1 resp. journal1a:
What do I need to add to the template to change the font of the first node to Arial? Thanks.
The WORD and POWERPOINT destination use style defintions that contain a SCHEME statement. So you have to base your style from the default styles.word style used by ODS WORD.
Find below a code sample that uses the default styles.word and makes some changes. Please note you have to open the word doc and update the TOC entry field to show the TOC entries, use the "Update Field" right mouse button action on the feld.
ODS WORD puts in this field:
Here is a code sample:
/*
* change ods path to say where to store
* styles
*/
ods path
(prepend) work.templates (update)
;
/*
* list default style for word destination
* NOTE: it contains a scheme statement, this is needed for ODS WORD
*/
proc template;
source Styles.Word ;
run;
/*
* create your own style based on default styles.word
*/
proc template;
define style styles.myword;
parent = Styles.Word;
class fonts /
'FixedStrongFont' = ("<monospace>, <MTmonospace>, monospace",11pt,bold)
'FixedEmphasisFont' = ("<monospace>, <MTmonospace>, monospace",11pt,italic)
'FixedFont' = ("<monospace>, <MTmonospace>, monospace",11pt)
'BatchFixedFont' = ("<monospace>, <MTmonospace>, monospace",8pt)
'docFont' = ("Arial, <sans-serif>, <MTsans-serif>",8pt)
;
class TOC1 /
marginbottom = 5pt
font = Fonts('docFont')
color = cx447200
;
class TOC2 /
marginleft = .14in
marginbottom = 5pt
font = Fonts('docFont');
class TOC3 /
marginleft = .28in
marginbottom = 5pt
font = Fonts('docFont');
end;
run;
/*
* use ODS WORD with styles and option to collect TOC
*
* NOTE: The doc entries are not displayed, you have to use the "Update Field"
* so that the toc is build in the word doc
*/
ods word file="c:\temp\toc_issue.docx"
style=styles.myword
options(contents="yes" toc_data='yes' );
title "first Report";
proc print data=sashelp.class;
run;
title "second report";
proc print data=sashelp.class;
run;
run;
ods word close;
Thanks! TOC uses Arial across all levels when I use word style as basis. Is there a way of adapting the journal1a style to include the scheme statement? The word style is quite far from my needed look & feel, mainly wrt. which lines in the tables are shown and which ones are not.
Well you do need to create your own style and apply customizations as you find them in other styles.
It is well worth reading the doc https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/odsug/p10mxeb6wxqfjgn1p5u0w4t8qf20.htm
as well as this paper https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2019/3235-2019.pdf
Both will contain examples and additional useful information.
You can use this code to look at a style definition:
proc template;
source Styles.Word ;
run;
I used some style definitions from styles.journal and applied it to a styles.word based style, give it a try
/*
* change ods path to say where to store
* styles
*/
ods path
(prepend) work.templates (update)
;
/*
* list default style for word destination
* NOTE: it contains a scheme statement, this is needed for ODS WORD
*/
proc template;
source Styles.Word ;
source styles.journal;
run;
/*
* create your own style based on default styles.word
*
* colors are coming from the SCHEME definition in styles.word
*/
proc template;
define style styles.myword;
parent = Styles.Word;
class fonts /
'FixedStrongFont' = ("<monospace>, <MTmonospace>, monospace",11pt,bold)
'FixedEmphasisFont' = ("<monospace>, <MTmonospace>, monospace",11pt,italic)
'FixedFont' = ("<monospace>, <MTmonospace>, monospace",11pt)
'BatchFixedFont' = ("<monospace>, <MTmonospace>, monospace",8pt)
'docFont' = ("Arial, <sans-serif>, <MTsans-serif>",8pt)
;
class HeadersAndFooters /
backgroundcolor = light1
;
class Table /
borderwidth = 1
borderspacing = 0
cellpadding = 7
frame = HSIDES
rules = GROUPS
bordercollapse = separate
borderstyle = solid
;
class TOC1 /
marginbottom = 5pt
font = Fonts('docFont')
color = accent1
;
class TOC2 /
marginleft = .14in
marginbottom = 5pt
font = Fonts('docFont')
;
class TOC3 /
marginleft = .28in
marginbottom = 5pt
font = Fonts('docFont')
;
end;
run;
/*
* use ODS WORD with styles and option to collect TOC
*
* Note that Microsoft Word does not automatically update the TOC
* when the document is loaded. You must instruct Microsoft Word
* to update the TOC manually.
* One way to do that is to type CTRL+A F9 on your keyboard.
*/
ods word file="c:\temp\toc_issue.docx"
style=styles.myword
options(contents="yes" toc_data="yes")
;
title "first Report";
proc print data=sashelp.class;
run;
title "second report";
proc print data=sashelp.class;
run;
run;
ods word close;
Thanks! I got most of the way there:
proc template;
define style styles.mywordstyle;
parent = styles.word;
scheme 'My style' /
followed_hyperlink = cx954f72
hyperlink = cx0563c1
accent6 = cx70AD47
accent5 = cx5B9BD5
accent4 = cxFFC000
accent3 = cxA5A5A5
accent2 = cxED7D31
accent1 = cx4472C4
light2 = cxe7e6e6
dark2 = cx44546A
light1 = cxFFFFFF
dark1 = cx000000
body_font = ("Arial", 10pt)
heading_font = ("Arial", 10pt, bold);
class SystemTitle /
fontsize = 10pt;
class SystemTitle2 /
fontweight=medium;
class SystemFooter /
fontsize = 9pt
fontweight = medium
just = left;
class Table /
cellpadding = 2
rules = groups;
class Header /
borderstyle = none
bordertopstyle = solid
borderbottomstyle = solid
rules = rows
paddingleft = 0pt
paddingright = 0pt
cellpadding = 2
margin = 0pt
background=grayf2
fontsize= 10pt;
class LineContent /
marginbottom = 6pt;
class Data /
borderstyle = none
borderbottomstyle = none
paddingleft = 0pt
paddingright = 0pt
cellpadding = 2
margin = 0pt
just = center;
class contenttitle /
content = "TABLE OF CONTENTS"
fontsize = 14pt
just = left
color=black;
end;
It now looks almost exactly as needed with a few remaining issues I was not able to fix myself:
title2 justify=right "Page ~{thispage} of ~{lastpage}";
are in bold font as opposed to normal. Do you know what class this is controlled by?
Tjank you for your help so far.
About 1, the CRLF you best contact technical support for that, since also the default style will create those
About 2, the spacing/padding for cells you do need to look at the differences in the style definitions, check the class Data
About 3, adding page information can also be achieved with the example below OPTIONS number; must be set. The style for a TITLE2 line is SystemTitle2 and so on.
class pageno / content = "Page {PAGE} of {NUMPAGES}" vjust=bottom just=center ;
Hi,
thank you for the suggestion, I have reached out to SAS support. Regarding the page number: I already have
class SystemTitle2 /
fontweight=medium;
in my template. It is just the page numbers themselves which are bold, not the entire row. I have tried your approach with
options number;
without further adjustments. While the font weight is correct, it put the page number in the footer whereas I need it in the header. Moreover, my actual header does contain more than just a page number (document number, creation date, etc.) so I don't think using options number is workable as I would effectively have to put a variable element into the template.
Using the definition below all text is the same
class systemtitle2 /
padding=0
color = cx0000ff
fontsize = 12pt
fontweight = medium
font = heading_font
;
Could it be something different about our Office versions then? On my machine the page numbers are still bold:
Find attached my docx file created.
I am using SAS version:
28 %put NOTE: &=sysvlong4;
NOTE: SYSVLONG4=9.04.01M7P08052020
Indeed, I do get bold page numbers
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.