m ake e asy s tyle t emplates u sing sas m acro barbara harlan
TRANSCRIPT
![Page 1: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/1.jpg)
MAKE EASY STYLE TEMPLATES USING SAS MACROBarbara Harlan
![Page 2: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/2.jpg)
ABOUT THE PAPER
This paper’s primary purpose is to show you how to create a style template so that you can output all of your SAS tables into Word without having to format in Word
Why not just format in Word? It saves time if you are output lots of tables that will need the same formatting (like the Dashboards). Also if the table needs to be twirked later (like editing an observation) you can quickly output the new table without having to redo all the formatting.
![Page 3: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/3.jpg)
OUTPUTTING SAS TABLESBarbara Harlan
![Page 4: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/4.jpg)
OUTPUT DELIVERY SYSTEM (ODS)
LISTING produces traditional SAS output HTML produces output for online viewing MARKUP produces output for markup
language tagsets (like Excel)
OUTPUT produces SAS output datasets PRINTER produces presentation-ready
printed reports RTF produces output suitable for
Microsoft Word reports
![Page 5: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/5.jpg)
ODS CODE
Syntax:ODS destination_name FILE=“filename”;* Your SAS procedure code here;ODS destination_name CLOSE;
Example:ODS RTF FILE= “myoutput.rtf” ;PROC PRINT DATA=sashelp.class;RUN;ODS RTF CLOSE;
Note:You must close the ODS for the file to be createdBe sure to attach the appropriate extension on the end of the
filename (i.e. “filename.rtf for an rtf destination”)
![Page 6: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/6.jpg)
STYLE OPTION
By default, ODS uses the default SAS style template for the selected destination. By using the STYLE= setting you can switch to a different SAS supplied style or your custom style.
Example: ODS RTF FILE= “myoutput.rtf” STYLE=brick; PROC PRINT DATA=sashelp.class; RUN; ODS RTF CLOSE;
![Page 7: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/7.jpg)
Obs Name Sex Age Height Weight1 Alfred M 14 69.0 112.5
2 Alice F 13 56.5 84.0
3 Barbara F 13 65.3 98.0
Sample of the default style for RTF output:
Sample of the “Brick” style supplied by SAS:
Obs Name Sex Age Height Weight1 Alfred M 14 69.0 112.5
2 Alice F 13 56.5 84.0
3 Barbara F 13 65.3 98.0
![Page 8: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/8.jpg)
WHAT YOU CAN DO WITH ODS AND EXCEL
![Page 9: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/9.jpg)
REQUIREMENTS
Base SAS Software, 9.1.3 or later, any operating system
recent version of the ExcelXP ODS tagset
http://support.sas.com/rnd/base/ods/odsmarkup/excltags.tpl
Microsoft Excel 2002 (aka Excel XP) or later
![Page 10: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/10.jpg)
BASIC CODE
ods tagsets.ExcelXP file='MyWorkbook.xml' style=sansPrinter options(<options>);
* Your SAS procedure code here;ods tagsets.ExcelXP close;
NoteOnly the PRINT, REPORT, and TABULATE procedures
support ODS style overrides
![Page 11: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/11.jpg)
OPTIONS- TITLES
EMBEDDED_FOOTNOTES default value: ‘No’EMBEDDED_TITLES values: ‘Yes’ ,‘No’
By default, the titles and footnotes of your output will not be displayed on the Excel worksheet. To display them, turn on the EMBEDDED_FOOTNOTES, EMBEDDED_TITLES options.
![Page 12: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/12.jpg)
OPTIONS- PRINT HEADERS
PRINT_HEADER value: character stringPRINT_FOOTER
PRINT_FOOTER=“&C&A&RPage &P of &N”;
Sheetname Page 1 of 12
![Page 13: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/13.jpg)
Values can be ‘None’ ‘All’ or a range
ODS tagsets.ExcelXP FILE="C:\Documents and Settings\Barbie\Desktop\TEMPLATE MACRO\AutofilterEx.xls" STYLE=XLsansprinter OPTIONS(autofilter="All" absolute_column_width='10');
PROC PRINT DATA=sasuser.autofilter NOOBS LABEL; VAR surveyid fixed_mobile
sitetype org siteid pat_volume epms epms_product emr q10_emr_product q10_emr_date;
LABEL pat_volume='Patient Volume' epms_product='EPMS Product' q10_emr_product='EMR Product' q10_emr_date='EMR Date Acquired';
RUN;
ODS tagsets.ExcelXP CLOSE;
OPTIONS- AUTOFILTER
![Page 14: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/14.jpg)
OPTIONS- BY GROUP PROCESSINGODS tagsets.ExcelXP FILE="C:\Documents and Settings\Barbie\
Desktop\TEMPLATE MACRO\AutofilterEx.xls" STYLE=XLsansprinter
OPTIONS(suppress_bylines=‘yes’ sheet_interval=‘bygroup’ sheet_label=‘ ‘ autofit_height=‘yes’;
PROC PRINT DATA=dash.pat_enc NOOBS LABEL;BY org; PAGEBY org; VAR period;VAR PC_Patients; VAR PC_Encounters; VAR BH_Patients; VAR BH_Encounters; VAR PC_and_BH_Patients;
RUN;
ODS tagsets.ExcelXP CLOSE;
![Page 15: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/15.jpg)
FROM SAS TO WORD AND NOT A DROP OF FORMATTING
![Page 16: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/16.jpg)
TEMPLATES
A template is a stored collection of formatting instructions that control the individual components of a report. There are over a 100 individual components or style elements that control your report.
ODS has two main types of templates: style templates and table templates.
Style templates provide output formatting for the entire SAS program while table templates are for selected procedure output within a program.
![Page 17: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/17.jpg)
Style templates provide specifications such as: Fonts Colors Borders Margins Backgrounds Cell spacing and padding
![Page 18: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/18.jpg)
TEMPLATE BROWSER
To explore templates, open the Template Browser by selecting VIEW →TEMPLATES from the Toolbar (Note: The Results window must be selected). The Template Browser window will be displayed.
![Page 19: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/19.jpg)
ANATOMY OF A STYLE TEMPLATE CODE
![Page 20: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/20.jpg)
THE MACRO
The complete macro contains two programs:The first, Custom Style Macro, contains the
style template and attribute references macros.
The second program, Custom Style Macro CALL, has the call statements for these macros.
There is a %include statement in the second program that will run the Custom Style Macro program when Custom Style Macro CALL is run.
![Page 21: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/21.jpg)
TIME OUT
![Page 22: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/22.jpg)
A little about macros…
Macros are programs that allow you to write dynamic code.
%MACRO macro_name (<parameters>);* Your SAS procedure code here;%MEND;%macro_name (<parameter values>);
Call Statement
It’s dynamic since you can change the values of the parameters without retyping the whole program.
![Page 23: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/23.jpg)
CUSTOM STYLE MACRO
![Page 24: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/24.jpg)
CUSTOM STYLE MACRO CALL
The call statement uses lots of notes throughout to make it clear which attributes you are changing.
Parameters are divided into sections, such as TITLE or COLUMN HEADER, based on what attributes they affect.
Above each parameter, there is a note that describes what the parameter controls in the output.
In order to change an attribute’s value, you simply replace the default value written in the call statement with the value you would like the attribute to have.
![Page 25: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/25.jpg)
%CUSTOM_STYLE_TEMPLATE (/****************** NAME OF STYLE TEMPLATE ***********************/STYLENAME=Superbowl, /****************** OUTPUT SETTINGS *******************************//****************** TITLE ***************************************//*Text size for titles from TITLE statement*/TITLESIZE= 12pt, /****************** FOOTNOTE ************************************//*Text size for footers from FOOTNOTE statement*/FOOTSIZE= 10pt, /*Font weight for footers from FOOTNOTE statement*/FOOTWEIGHT= Medium, /****************** COLUMN HEADERS ******************************//*Text size for COLUMN and ROW headers in table*/HSIZE= 11pt, /*Vertical justification of COLUMN and ROW headers in table*/VHJUST= bottom, /*Background color for COLUMN headers in table*/CHBACKGROUND= palegoldenrod, /****************** ROW HEADERS *********************************//*Background color for ROW headers in table*/RHBACKGROUND= palegoldenrod, /****************** DATA CELLS ***********************************//*Justification of DATA in cells*/DATAJUST= right,/*Vertical justification of DATA in cells*/VDATAJUST= bottom,/****************** TABLE APPEARANCE ******************************//*Padding between cell border and cell contents in TABLE*/CELLPADDING= 5pt, /*Type of rules (lines) that go inside TABLE (see %frames_and_rules for a list of values)*/RULES= rows,/*Width of FRAMES (RULE width is dictated by cellspacing)*/BORDERWIDTH= 1.5pt );
QUIT;
![Page 26: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/26.jpg)
APPLYING YOUR CUSTOM STYLE TEMPLATE
PROC FORMAT; VALUE yesno 1='Yes‘ 0='No‘ .='Missing'; VALUE $OrgType 'PC'='Primary Care‘ 'BH'='Behavioral Health'; PICTURE pctfmt (default=7) low-high='009.9%'; RUN;
ODS RTF FILE="C:\Documents and Settings\Barbie\Desktop\TEMPLATE MACRO\TemplateEx.rtf" STYLE=Superbowl STARTPAGE=yes BODYTITLE;
TITLE 'Table 3: Availability of Electronic Practice Management Systems (EPMS)'; FOOTNOTE 'Patient volumes over 18 months (Sept 2007 to March 2009)'; FOOTNOTE2 'Volume data not available for 3 sites';
PROC TABULATE DATA=sasuser.autofilter FORMAT=comma7.; CLASS sitetype epms emr; VAR pat_volume; TABLE sitetype=' ' all='All Sites'*{style={font_weight=bold}},epms*(n
rowpctn*F=pctfmt7. pat_volume='Volume') all='Total'*(n rowpctn*F=pctfmt7.) / misstext='0' BOX={LABEL="Organization Type"}; KEYLABEL n='N' sum=' ' rowpctn='%'; FORMAT sitetype $orgtype. epms emr yesno.;
RUN;
ODS RTF CLOSE;
![Page 27: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/27.jpg)
NOTE
Will not affect graphs! To customize your graphs you must use
GOPTIONS SAS 9.2 now has ways you can make “graph
templates”… Future paper? ;) Graphs that output to Word will output as
pictures- you will not be able to edit them!
![Page 28: M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ee45503460f94bf3b4d/html5/thumbnails/28.jpg)
WHERE DO I GET THIS MAGICAL MACRO?
The code is attached to the end of my paper It is also available on my new website
www.bharlan.weebly.com It will be placed in a public folder on the L
drive