Presentation is loading. Please wait.

Presentation is loading. Please wait.

M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan.

Similar presentations


Presentation on theme: "M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan."— Presentation transcript:

1 M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan

2 A BOUT 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.

3 O UTPUTTING SAS T ABLES Barbara Harlan

4 O UTPUT D ELIVERY S YSTEM (ODS) LISTINGproduces traditional SAS output HTMLproduces output for online viewing MARKUPproduces output for markup language tagsets (like Excel) OUTPUTproduces SAS output datasets PRINTERproduces presentation-ready printed reports RTFproduces output suitable for Microsoft Word reports

5 ODS C ODE 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 created Be sure to attach the appropriate extension on the end of the filename (i.e. “filename.rtf for an rtf destination”)

6 S TYLE O PTION 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;

7 ObsNameSexAgeHeightWeight 1AlfredM1469.0112.5 2AliceF1356.584.0 3BarbaraF1365.398.0 Sample of the default style for RTF output: Sample of the “Brick” style supplied by SAS: ObsNameSexAgeHeightWeight 1 AlfredM1469.0112.5 2 AliceF1356.584.0 3 BarbaraF1365.398.0

8 W HAT YOU CAN DO WITH ODS AND E XCEL

9 R EQUIREMENTS 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/e xcltags.tpl Microsoft Excel 2002 (aka Excel XP) or later

10 B ASIC C ODE ods tagsets.ExcelXP file='MyWorkbook.xml' style=sansPrinter options( ); * Your SAS procedure code here; ods tagsets.ExcelXP close; Note Only the PRINT, REPORT, and TABULATE procedures support ODS style overrides

11 O PTIONS - T ITLES EMBEDDED_FOOTNOTESdefault value: ‘No’ EMBEDDED_TITLESvalues: ‘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.

12 O PTIONS - P RINT H EADERS PRINT_HEADERvalue: character string PRINT_FOOTER PRINT_FOOTER=“&C&A&RPage &P of &N”; SheetnamePage 1 of 12

13 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; O PTIONS - A UTOFILTER

14 O PTIONS - B Y G ROUP P ROCESSING ODS 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;

15 F ROM SAS TO W ORD AND NOT A DROP OF FORMATTING

16 T EMPLATES 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.

17 Style templates provide specifications such as: Fonts Colors Borders Margins Backgrounds Cell spacing and padding

18 T EMPLATE B ROWSER 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.

19 A NATOMY OF A S TYLE T EMPLATE C ODE

20 T HE M ACRO 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.

21

22 A little about macros… Macros are programs that allow you to write dynamic code. %MACRO macro_name ( ); * Your SAS procedure code here; %MEND; %macro_name ( ); Call Statement It’s dynamic since you can change the values of the parameters without retyping the whole program.

23 C USTOM S TYLE M ACRO

24 C USTOM S TYLE M ACRO 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.

25 %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;

26 A PPLYING Y OUR C USTOM S TYLE T EMPLATE PROC FORMAT; VALUEyesno 1='Yes‘ 0='No‘.='Missing'; VALUE$OrgType 'PC'='Primary Care‘ 'BH'='Behavioral Health'; PICTUREpctfmt (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;

27 N OTE 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!

28 W HERE 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 www.bharlan.weebly.com It will be placed in a public folder on the L drive


Download ppt "M AKE E ASY S TYLE T EMPLATES U SING SAS M ACRO Barbara Harlan."

Similar presentations


Ads by Google