Macro Variables Make Macro Variables Make Life Easier: Life Easier: Applications with Applications with SAS® to Excel SAS® to Excel Misty Johnson Misty Johnson Research Analyst-Senior Research Analyst-Senior State of Wisconsin Department of Health State of Wisconsin Department of Health Services Services Madison, WI, USA Madison, WI, USA MWSUG 2010 Milwaukee, WI MWSUG 2010 Milwaukee, WI Paper 40-2010 Paper 40-2010
24
Embed
Macro Variables Make Life Easier: Applications with SAS® to Excel Misty Johnson Research Analyst-Senior State of Wisconsin Department of Health Services.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Macro Variables Make Life Macro Variables Make Life Easier: Applications with Easier: Applications with
SAS® to ExcelSAS® to ExcelMisty JohnsonMisty Johnson
Research Analyst-SeniorResearch Analyst-Senior
State of Wisconsin Department of Health ServicesState of Wisconsin Department of Health Services
Research Analyst, WI DHSResearch Analyst, WI DHS Medicaid WaiversMedicaid Waivers
Reports with sensitive info for CountiesReports with sensitive info for Counties Don’t mix up the Counties!!!Don’t mix up the Counties!!! HIPAA violation!!!HIPAA violation!!!
Repetitive effortsRepetitive efforts Macros and macro variables simplify taskMacros and macro variables simplify task
Use macro variables toUse macro variables to Simplify repetitive actionsSimplify repetitive actions Know what you’re pullingKnow what you’re pulling Verify report before printingVerify report before printing Guide Dynamic Data Exchange (DDE)Guide Dynamic Data Exchange (DDE)
Set Macro Variables on TopSet Macro Variables on Top
*>ENTER DATA YEAR HERE>>>>>>; %LET YEAR=2010; *>ENTER AGENCY NUMBER HERE>; %LET C_AGENCY=201300; *>ENTER AGENCY NAME HERE>>>; %LET AGENAME=Dane; *>ENTER REPORT NAME HERE>>>>; %LET RPTNAME=Dane HSD L300; *>ENTER PASSWORD HERE>>>>>>>; %LET PASSWORD=Dane2; *>ENTER RECIPIENT HERE>>>>>>>; %LET RECIP=Jean French; *>ENTER PAPER ORIENTATION>>>>; %LET ORIENT=Landscape; *>ENTER PAPER SIZE>>>>>>>>>>>>; %LET PAPER1=Legal; **++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
Tell the Output “Where to go…”Tell the Output “Where to go…”DATA _NULL_;
SET CY&YEAR..asofdate;CALL SYMPUT('currdtlong',put(today(),DATE9.));CALL SYMPUT('asofdatelong',PUT(asofdate,DATE9.));
/* INVOKE MACRO TO WRITE TO EXCEL IF CORRECT COUNTY */
%PRINT_REPORT; RUN;
PROC DBLOAD = Ugly….PROC DBLOAD = Ugly….
SPC ServiceTotal
Cost
095.01 Participant Cost Share ($4,684)
107.50
Transportation Specialized - Items $4,097
112.55
Specialized Medical Supplies - Items $163
202.01
Adult Family Home 1 to 2 Beds - Days $17,216
Would like to see this… but how?Would like to see this… but how?
SPC Service Total Cost
095.01 Participant Cost Share ($4,684)
107.50 Transportation Specialized - Items $4,097
112.55 Specialized Medical Supplies - Items $163
202.01 Adult Family Home 1 to 2 Beds - Days $17,216
Behold, the Power of……Behold, the Power of……
Dynamic Data ExchangeDynamic Data Exchange
What DDE can do for you…What DDE can do for you…
Format Excel documents FOR youFormat Excel documents FOR you In SAS codeIn SAS code Examples:Examples:
Change font type, font size, font colorChange font type, font size, font color Add headers, footersAdd headers, footers Set margins, paper sizeSet margins, paper size Apply password protectionApply password protection And many more…And many more…
See MWSUG 2007 paper # A01-2007See MWSUG 2007 paper # A01-2007
What you can do for DDE …What you can do for DDE …
Many settings within DDE…Many settings within DDE… Many repetitive settings…Many repetitive settings… Remember what you set them to…Remember what you set them to… Solution?Solution?
Use macro variables!!!Use macro variables!!!
Pre-work for DDEPre-work for DDE
Communicate to DDE:Communicate to DDE: Paper orientationPaper orientation Paper sizePaper size Number of observations (rows)Number of observations (rows) Number of variables (columns)Number of variables (columns)
Set Macro Variables on TopSet Macro Variables on Top
*>ENTER DATA YEAR HERE>>>>>>; %LET YEAR=2010; *>ENTER AGENCY NUMBER HERE>; %LET C_AGENCY=201300; *>ENTER AGENCY NAME HERE>>>; %LET AGENAME=Dane; *>ENTER REPORT NAME HERE>>>>; %LET RPTNAME=Dane HSD L300; *>ENTER PASSWORD HERE>>>>>>>; %LET PASSWORD=Dane2; *>ENTER RECIPIENT HERE>>>>>>>; %LET RECIP=Jean French; *>ENTER PAPER ORIENTATION>>>>; %LET ORIENT=Landscape; *>ENTER PAPER SIZE>>>>>>>>>>>>; %LET PAPER1=Legal; **++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
Within DDE: Format Output Within DDE: Format Output
Within DDE: Format Output Within DDE: Format Output * The hard way:;
PUT '[PAGE.SETUP("&L REPORT NAME: Dane HSD L300' '0d'x 'RUNDATE: 11OCT2010 FOR: Jean French' '0d'x 'AUTHOR: Misty Johnson SOURCE: 2010 HSRS LTS Module","&L &F &R Page 1 of 100“ ,.25,.25,.75,.5, FALSE,TRUE,TRUE,TRUE,2,5,100,"AUTO",2,TRUE,600,.25,.25)]';
*Easier.;
PUT %unquote(%str (%'[PAGE.SETUP("&L REPORT NAME: &RPTNAME.' '0d'x 'RUNDATE: &D FOR: &RECIP.' '0d'x 'AUTHOR: Misty Johnson SOURCE: &YEAR. HSRS LTS Module","&L &F &R Page &P of &N",.25,.25,.75,.5, FALSE,TRUE,TRUE,TRUE,&ORIENTATION.,&PAPER.,100,"AUTO",2,TRUE,600,.25,.25)]%'));
Within DDE: Save and Apply Within DDE: Save and Apply Password to Final OutputPassword to Final Output
PUT %unquote (%str(%'[SAVE.AS(&PATH1.,,"&PASSWORD.")]%'));
ConclusionsConclusions
Macro variables make life easierMacro variables make life easier Use for repetitive actionsUse for repetitive actions Keep things straight!Keep things straight!
DDE is awesome! Check it out!DDE is awesome! Check it out!