Presentation is loading. Please wait.

Presentation is loading. Please wait.

Macro Variables Make Life Easier: Applications with SAS® to Excel Misty Johnson Research Analyst-Senior State of Wisconsin Department of Health Services.

Similar presentations


Presentation on theme: "Macro Variables Make Life Easier: Applications with SAS® to Excel Misty Johnson Research Analyst-Senior State of Wisconsin Department of Health Services."— Presentation transcript:

1 Macro Variables Make Life Easier: Applications with SAS® to Excel Misty Johnson Research Analyst-Senior State of Wisconsin Department of Health Services Madison, WI, USA MWSUG 2010 Milwaukee, WI Paper

2 Introduction Research Analyst, WI DHS Research Analyst, WI DHS Medicaid Waivers Medicaid Waivers Reports with sensitive info for Counties Reports with sensitive info for Counties Dont mix up the Counties!!! Dont mix up the Counties!!! HIPAA violation!!! HIPAA violation!!! Repetitive efforts Repetitive efforts Macros and macro variables simplify task Macros and macro variables simplify task Minimize error potential too! Minimize error potential too!

3 Abstract Use macro variables to Use macro variables to Simplify repetitive actions Simplify repetitive actions Know what youre pulling Know what youre pulling Verify report before printing Verify report before printing Guide Dynamic Data Exchange (DDE) Guide Dynamic Data Exchange (DDE)

4 Set 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; * * ;

5 Tell the Output Where to go… DATA _NULL_; SET CY&YEAR..asofdate; CALL SYMPUT('currdtlong',put(today(),DATE9.)); CALL SYMPUT('asofdatelong',PUT(asofdate,DATE9.)); RUN; >ENTER OUTPUT PATH HERE>>>>; %LET PREPATH1= "H:\TEMP\PreRpt_for_&agename._rtn_&currdtlong..xls"; %LET PATH1= "H:\&YEAR.\&AGENAME.\Rpt_for_&agename._&year._asof_&as ofdatelong._rtn_&currdtlong..xls";

6 Create Report

7 Before you print, VERIFY!! Grab Agency Name from the top line Grab Agency Name from the top line Is it what you thought? Is it what you thought? Yes? Then ship to Excel Yes? Then ship to Excel No? Do nothing further No? Do nothing further

8 Before you print, VERIFY!! DATA _NULL_; SET REPORT; IF _N_=1 THEN CALL SYMPUT('AGENCYNAME',PUT(AGENCY,$25.)); RUN; DATA _NULL_; SET CY&YEAR..asofdate; IF (LOWCASE(SCAN("&AGENAME.",1)))= (LOWCASE(SCAN("&AGENCYNAME.",1))) THEN CALL SYMPUT('ANSWER',PUT("YES, $5.)); ELSE CALL SYMPUT('ANSWER',PUT("NO, $5.)); RUN;

9 Ok to print?? %MACRO PRINT_REPORT; %IF &ANSWER.=YES %THEN %DO; PROC DBLOAD DBMS=EXCEL DATA= REPORT; PATH=&PREPATH1.; PUTNAMES=YES; LIMIT=0; label; reset all; LOAD; RUN; %END; RUN; %MEND PRINT_REPORT; /* INVOKE MACRO TO WRITE TO EXCEL IF CORRECT COUNTY */ %PRINT_REPORT; RUN;

10 PROC DBLOAD = Ugly…. PROC DBLOAD = Ugly…. SPCServiceTotal Cost Participant Cost Share($4,684) Transportation Specialized - Items$4, Specialized Medical Supplies - Items$ Adult Family Home 1 to 2 Beds - Days$17,216

11 Would like to see this… but how? Would like to see this… but how? SPCServiceTotal Cost Participant Cost Share($4,684) Transportation Specialized - Items$4, Specialized Medical Supplies - Items$ Adult Family Home 1 to 2 Beds - Days$17,216

12 Behold, the Power of…… Dynamic Data Exchange

13 What DDE can do for you… Format Excel documents FOR you Format Excel documents FOR you In SAS code In SAS code Examples: Examples: Change font type, font size, font color Change font type, font size, font color Add headers, footers Add headers, footers Set margins, paper size Set margins, paper size Apply password protection Apply password protection And many more… And many more… See MWSUG 2007 paper # A

14 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!!!

15 Pre-work for DDE Communicate to DDE: Communicate to DDE: Paper orientation Paper orientation Paper size Paper size Number of observations (rows) Number of observations (rows) Number of variables (columns) Number of variables (columns)

16 Set 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; * * ;

17 Paper Size, Orientation %GLOBAL ORIENTATION PAPER; OPTIONS SYMBOLGEN; %MACRO COMPILE_DDE(ORIENT=,PAPER1=); %IF &ORIENT.=Portrait %THEN %LET ORIENTATION=1; %ELSE %LET ORIENTATION=2; %IF &PAPER1.=Letter %THEN %LET PAPER=1; %ELSE %LET PAPER=5; %MEND COMPILE_DDE; %COMPILE_DDE(ORIENT=&ORIENT.,PAPER1=&PAPER1.); %PUT ORIENTATION=&ORIENTATION.; %PUT PAPER=&PAPER.;

18 Obs x Vars = Rows x Cols %let nvar= %sysfunc(attrn(%sysfunc(open(&syslast.,i)),nvars)); %let nobs= %EVAL( %sysfunc(attrn(%sysfunc(open(&syslast.,i)),nobs))+1); %put nvar=&nvar.; %put nobs=&nobs.; Credit: SAS TECH SUPPORT: Usage Note 8743

19 Put DDE to work Use it in a macro Use it in a macro Use macro variables to guide it! Use macro variables to guide it! %MACRO FORMATME (PREPATH1=, PATH1=, PASSWORD=, NVAR=, NOBS=, ORIENTATION=, PAPER=); /* DDE CODE */ %MEND FORMATME %FORMATME (PREPATH1=&PREPATH1.,PATH1=&PATH1.,PASSWORD=&PASSWORD., NVAR=&NVAR.,NOBS=&NOBS., ORIENTATION=&ORIENTATION.,PAPER=&PAPER.);

20 Within DDE: Format Output

21 * 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,6 00,.25,.25)]%'));

22 Within DDE: Save and Apply Password to Final Output PUT %unquote (%str(%'[SAVE.AS(&PATH1.,,"&PASSWORD.")]%'));

23 Conclusions Macro variables make life easier Macro variables make life easier Use for repetitive actions Use for repetitive actions Keep things straight! Keep things straight! DDE is awesome! Check it out! DDE is awesome! Check it out!

24 Questions/ Contact Info Misty Johnson Thank you!!


Download ppt "Macro Variables Make Life Easier: Applications with SAS® to Excel Misty Johnson Research Analyst-Senior State of Wisconsin Department of Health Services."

Similar presentations


Ads by Google