Documente Academic
Documente Profesional
Documente Cultură
2008 AIR Forum Seattle, Washington Ray Wallace (rwallace@wsu.edu) Washington State University View Presentation at http://www.ir.wsu.edu/
Presentation Overview
SAS Tagsets (Excel features from SAS) Style (Get it to look right) Department Looping (Macros)
What is a Tagset?
Adds tags to output using ODS
Get the latest tagset code http://support.sas.com/rnd/base/ods/odsmarkup/index.html New version 1.86 available as of April 2008
Install the Latest Tagset Download the latest version from support.sas.com Save the *.tpl file Open the *.tpl file in SAS Run it
How Does A Tagset Work? A Tagset is just another ODS destination. E.g., listing html pdf Tagsets (such as ExcelXP)
Manage ods
Close
Get A List Of The Available Tagsets proc template; list tagsets; run;
User-defined tagsets will be located in SASUSER.TEMPLAT. Tagsets provided by SAS are in SASHELP.TMPLMST
Works with the ODS Define with proc template When issuing an ODS command style is implied
Ex: ods tagsets.excelxp file = foo.xls; is the same as ods tagsets.excelxp file = foo.xls style = default;
Building a Report
Department Level Accreditation Data Want a consolidated and concise report of information from various topic areas Display multiple years of data Easy for users to read Familiar format (Excel) Metadata/data definitions Extensible (able to add reports easily) Printable
ExcelXP Options
Over 60 options and controls allow SAS to control Excel. Including Table of Contents/Index Customizing column widths Zooming Header / footer control Excel comments Repeat cells Get Documentation: Sheet naming ods Tagsets.ExcelXP file = "c:\test.xls Page orientation options (doc='help') ;
ods tagsets.Excelxp close ;
ExcelXP Options
Determine the zoom level on the worksheet
ods tagsets.excelxp options (zoom=88) ; 100 is the default
ExcelXP Options
Repeat header row on each page for printing
ods tagsets.excelxp options(row_repeat=header); Also Use these options none -default 1-3 5
ExcelXP Options
Create a sheet which has links names of all other worksheets.
ods tagsets.excelxp options(index=yes);
ExcelXP Options
Name the worksheets
ods tagsets.excelxp options (sheet_name=Overview Data)
ExcelXP Options
When to create a new sheet
ods tagsets.excelxp options (sheet_interval=proc) ; Table is the default Also use page, bygroup, proc, none
ExcelXP Options
Format the page for printing
ods tagsets.excelxp options (orientation=landscape);
ExcelXP Options
Tells Excel the width of each column
ods tagsets.excelxp options (default_Column_Width=12,9,6,6,6,6,6,8);
Using Style
Then
1.
2.
style(header)=hrheader
(predefined in irstyle_xl)
2.
Direct
style(column)={font_size=2}
Macro Looping
To have your program create an Excel file for each academic department Use a macro!
%macro deptloop(dept); SAS CODE %mend deptloop; %deptloop(CHEM)
Macro Looping
What goes in the SAS CODE portion of the program? First open the ODS destination and manage options for the first report.
ods tagsets.ExcelXP file = c:\Report for &dept..xls style=irstyle_xl options (sheet interval=proc sheet_name=First dept report);
Macro Looping
What goes in the SAS CODE portion of the program? Then maybe some traffic lighting
proc format; value traffic low - <10 10 - <50 50 - high
Macro Looping
Macro Looping
What goes in the SAS CODE portion of the program? Use ExcelXP options again for the next report
ods tagsets.ExcelXP options(sheet_name=Second Dept Report default_Column_Width=12,6,6,6,6,6); frozen_header=2 );
Macro Looping What goes in the SAS CODE portion of the program? Write the second report.
proc report data = deptreport2 nowd missing ; column subject acad_year, fte; define subject/ group Course Subject; define acad_year / across AY define fte /analysis sum FTE style(column)={tagattr="format:##0.0}; where dept = &dept; run;
Macro Looping What goes in the SAS CODE portion of the program? Now finish it up.
ods tagsets.ExcelXP close;
This closes the ODS and finishes creating the Excel file. Then the macro must end and... %mend deptloop;
SAS must call the macro for the code to actually run. %deptloop(CHEM)
Macro Looping What if you have 100+ department and dont want to write 100+ %deptloop() macro calls?
create macro var for a percent sign %let pctsign=%str(%%); This will write all your macro calls for you data _null_ ; set dept_list ; end = lastobs; file "c:\call the macro program.txt"; put "&pctsign" "deptloop (" dept +(1*-1) ")" ; run; This will run all your macro calls for you %include "c:\ call the macro program.txt" ;
Question? Contact me at
Ray Wallace (rwallace@wsu.edu) Washington State University
Resources
SAS-L newsgroup SAS emits SAS tech support
Tagset Links
http://support.sas.com/events/sasglobalforum/index.html http://support.sas.com/rnd/base/ods/odsmarkup/
Style Links
http://www.laurenhaworth.com/publications/195-28.pdf http://www.laurenhaworth.com/publications/132-30.pdf http://www.guptaprogramming.com/images/ODS_Custom.pdf