SlideShare a Scribd company logo
10 Steps to Easier SAS Code Maintenance Jessica Hampton, CIGNA 09/02/11
Introduction USE: Simple organization techniques Macro variables Parameterized macros  Appropriate documentation TO: Reduce hard coding Reduce code volume Make regularly updated values easy to find 09/02/11
Steps 1-2: Chunking & Numbering Break up large processes into individual programs Number programs in order of process flow 09/02/11
Steps 1-2: example 09/02/11
Step 3: Initial Setup Create an initial setup program for: Libnames Remote sessions Macro variables System options 09/02/11
Step 3: Initial Setup example 09/02/11
Step 4: Final Cleanup Create a final cleanup program to: Download files on remote server Delete interim files no longer needed Create final table listing and export “data dictionary” to Excel Use data dictionary to identify problems Unexpected row counts Unnecessarily long fields 09/02/11
Step 4: Final Cleanup 09/02/11
Step 5: Macro Variables Use macro variables for date selection criteria: … where ben_feat_eff_dt <=”&startdate”d and ben_feat_can_dt>”&startdate”d; … Case when HRA_Month_Start = 1  Then &yearmonth + HRA_Month_Start  Else &yearlastmonth + HRA_Month_Start  End as HRA_Prog_Yr_Start,… 09/02/11
Step 6: Macro Variables Use macro variables for file names: Create Table qry_Ben_Feat_&year as… Proc Download Data = WHP.Internal_EPop_&year OUT=HRA.Internal_EPop_&year; Libname PPO “/projects/hedis/ppo&year”; 09/02/11
Step 7: Macro Variables Use macro variables for frequently updated/referenced lists: %let markets = %str('WA','OR','CA','CO','TN','FL','SC','MD','DC','OH','NJ','NY','CT'); /*eValu8 markets*/ %let diabetes = %str('25000','25001','25002','25003','25010','25011','25012','25013','25020','25021','25022','25023','25030','25050','25051','25052','25053','25060','25061','25062','25063','25070','25071','25072','25073','25080','25031','25032','25033','25040','25041','25042','25043','25081','25082','25083','25090','25091','25092','25093');/*diabetes diagnosis codes, used in measures 1,3,14,16*/ SELECT code  INTO: opnaiprev separated by '&quot;,&quot;' /*outpatient, non-acute inpatient revenue proc codes*/ FROM ref.ect WHERE description in('outpatient','nonacute_inpatient') AND typeofcode='RevCode' AND tablename='CDC_C' ; 09/02/11
Step 7: (continued) Code is shorter  Easier to understand Can update all in one place WHERE svc_dt BETWEEN &quot;01jan&yearp&quot;d AND &quot;31dec&year&quot;d /*current year or year prior*/ AND (diag_cd1 IN (&diagcd) OR diag_cd2 IN (&diagcd) OR diag_cd3 IN (&diagcd))/*primary or secondary diagnosis code*/ AND (proc_cd IN(&quot;&aipedcpt&quot;)/*acute inpatient or ED cpt codes*/ OR (proc_cd IN(&quot;&aipedrev&quot;) 09/02/11
Step 8: Parameterized Macros Analyze processes for similarities Identify re-usable pieces of code Convert to parameterized macros Reduce code volume 09/02/11
Step 8: Analysis 09/02/11 transfers immunocompromised state proc codes immunocompromised state diagnoses *For 11, also exclude anemia principal or secondary diagnoses *For 12, also exclude principal or secondary kidney disorder diagnoses include discharges with  principal  diagnosis code specified:  bacterial pneumonia UTI 11,12 transfers cardiac procedure codes in any field *For 7 only, also exclude kidney disease diagnoses if accompanied by hemodialysis procs include discharges with  principal  diagnosis code specified:  hypertension CHF angina 7*,8,13 transfers include discharges with  principal  diagnosis code specified: diabetes short term complications diabetes long term complications hypovolemia uncontrolled diabetes 1,3,10,14 Exclusions Numerator Measure
Step 8: Parameterized Macro 09/02/11 %macro transfer(filename=)/STORE SOURCE; /*identify and delete transfers from numerator*/ CREATE TABLE &filename._TRANS AS SELECT B.conf_id, B.admit_dt, A.disch_dt  FROM PQI.&filename A JOIN PQI.&filename B ON A.rhmo=B.rhmo AND A.bkey=B.bkey  AND A.disch_dt BETWEEN B.admit_dt AND intnx('DAY',B.admit_dt,-1)/*re-admitted within 24 hours of discharge date*/  WHERE A.conf_id <> B.conf_id  AND A.src_sys_prov_id <> B.src_sys_prov_id /*transferred from different facility*/ ; DELETE  FROM PQI.&filename  WHERE conf_ID IN  (SELECT conf_id FROM &filename._TRANS) ; %mend transfer;
Step 8: Putting it Together 09/02/11
Steps 9-10: Documentation Comment code Use program headers Program name Developer name Date created Purpose Update information Programmer name Date modified Reason for modification Input/output tables 09/02/11
Conclusion Break up large processes into smaller steps Number programs in order of process flow Create initial setup program Create final cleanup program Use macro variables for date selection criteria Use macro variables for file names Use macro variables for long lists that need frequent updating and/or are referenced frequently Use parameterized macros for similar processes Document using comments Document using program headers 09/02/11
References SAS Institute Inc.  2009 .  SAS 9.2 Macro Language Reference .  Cary, NC: SAS Institute, Inc. Patridge, C.  Best Practices: Using SAS Effectively/Efficiently .  HASUG presentation 2/24/2011. Rhodes, D.  If You Have Programming Standards, Please Raise Your Hand: An Everyman’s Guide .  http://www.nesug.org/Proceedings/nesug10/ma/ma10.pdf (5/31/2011). 09/02/11
Acknowledgement SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries.  ®   indicates USA   registration. Other brand and product names are registered trademarks or trademarks of their respective companies. 09/02/11

More Related Content

PPT
Set and Merge
PPT
Conditional statements in sas
PPT
Conditional Clauses
PPTX
Market Basket Analysis in SAS
PPTX
SAS basics Step by step learning
PDF
Stored-Procedures-Presentation
KEY
CICONF 2012 - Don't Make Me Read Your Mind
PPTX
Unit3 overview of_c_programming
Set and Merge
Conditional statements in sas
Conditional Clauses
Market Basket Analysis in SAS
SAS basics Step by step learning
Stored-Procedures-Presentation
CICONF 2012 - Don't Make Me Read Your Mind
Unit3 overview of_c_programming

Similar to Steps to Easier SAS Code Maintenance (20)

PPTX
Final Project Presentation
PPT
"Running CF in a Shared Hosting Environment"
PPTX
Back-2-Basics: Exception & Event Instrumentation in .NET
PPTX
Back-2-Basics: Exception & Event Instrumentation in .NET
PDF
MSSQL Queries.pdf
DOC
PPT
Capistrano Overview
DOC
KSK1014 COMPUTER SYSTEM HARDWARE INSTALLATION.doc
PPT
Data Access Mobile Devices
PDF
Habits of Effective SAS Programmers
PPT
PCD - Process control daemon
PDF
6048618 cloning-procedure-of-r12-single-tier
PPT
Evolutionary db development
PPTX
SPOS UNIT 2 MACRO NOTES SPOS UNIT 2 MACRO NOTESSPOS UNIT 2 MACRO NOTESSPOS...
DOC
Cis 170 c ilab 7 of 7 sequential files
PPT
Program logic and design
PDF
Flow based programming in golang
PPT
Daniel Egan Msdn Tech Days Oc Day2
PDF
Managing Changing Data: Part 2
PPTX
Recharge_report_Automation
Final Project Presentation
"Running CF in a Shared Hosting Environment"
Back-2-Basics: Exception & Event Instrumentation in .NET
Back-2-Basics: Exception & Event Instrumentation in .NET
MSSQL Queries.pdf
Capistrano Overview
KSK1014 COMPUTER SYSTEM HARDWARE INSTALLATION.doc
Data Access Mobile Devices
Habits of Effective SAS Programmers
PCD - Process control daemon
6048618 cloning-procedure-of-r12-single-tier
Evolutionary db development
SPOS UNIT 2 MACRO NOTES SPOS UNIT 2 MACRO NOTESSPOS UNIT 2 MACRO NOTESSPOS...
Cis 170 c ilab 7 of 7 sequential files
Program logic and design
Flow based programming in golang
Daniel Egan Msdn Tech Days Oc Day2
Managing Changing Data: Part 2
Recharge_report_Automation
Ad

Steps to Easier SAS Code Maintenance

  • 1. 10 Steps to Easier SAS Code Maintenance Jessica Hampton, CIGNA 09/02/11
  • 2. Introduction USE: Simple organization techniques Macro variables Parameterized macros Appropriate documentation TO: Reduce hard coding Reduce code volume Make regularly updated values easy to find 09/02/11
  • 3. Steps 1-2: Chunking & Numbering Break up large processes into individual programs Number programs in order of process flow 09/02/11
  • 5. Step 3: Initial Setup Create an initial setup program for: Libnames Remote sessions Macro variables System options 09/02/11
  • 6. Step 3: Initial Setup example 09/02/11
  • 7. Step 4: Final Cleanup Create a final cleanup program to: Download files on remote server Delete interim files no longer needed Create final table listing and export “data dictionary” to Excel Use data dictionary to identify problems Unexpected row counts Unnecessarily long fields 09/02/11
  • 8. Step 4: Final Cleanup 09/02/11
  • 9. Step 5: Macro Variables Use macro variables for date selection criteria: … where ben_feat_eff_dt <=”&startdate”d and ben_feat_can_dt>”&startdate”d; … Case when HRA_Month_Start = 1 Then &yearmonth + HRA_Month_Start Else &yearlastmonth + HRA_Month_Start End as HRA_Prog_Yr_Start,… 09/02/11
  • 10. Step 6: Macro Variables Use macro variables for file names: Create Table qry_Ben_Feat_&year as… Proc Download Data = WHP.Internal_EPop_&year OUT=HRA.Internal_EPop_&year; Libname PPO “/projects/hedis/ppo&year”; 09/02/11
  • 11. Step 7: Macro Variables Use macro variables for frequently updated/referenced lists: %let markets = %str('WA','OR','CA','CO','TN','FL','SC','MD','DC','OH','NJ','NY','CT'); /*eValu8 markets*/ %let diabetes = %str('25000','25001','25002','25003','25010','25011','25012','25013','25020','25021','25022','25023','25030','25050','25051','25052','25053','25060','25061','25062','25063','25070','25071','25072','25073','25080','25031','25032','25033','25040','25041','25042','25043','25081','25082','25083','25090','25091','25092','25093');/*diabetes diagnosis codes, used in measures 1,3,14,16*/ SELECT code INTO: opnaiprev separated by '&quot;,&quot;' /*outpatient, non-acute inpatient revenue proc codes*/ FROM ref.ect WHERE description in('outpatient','nonacute_inpatient') AND typeofcode='RevCode' AND tablename='CDC_C' ; 09/02/11
  • 12. Step 7: (continued) Code is shorter Easier to understand Can update all in one place WHERE svc_dt BETWEEN &quot;01jan&yearp&quot;d AND &quot;31dec&year&quot;d /*current year or year prior*/ AND (diag_cd1 IN (&diagcd) OR diag_cd2 IN (&diagcd) OR diag_cd3 IN (&diagcd))/*primary or secondary diagnosis code*/ AND (proc_cd IN(&quot;&aipedcpt&quot;)/*acute inpatient or ED cpt codes*/ OR (proc_cd IN(&quot;&aipedrev&quot;) 09/02/11
  • 13. Step 8: Parameterized Macros Analyze processes for similarities Identify re-usable pieces of code Convert to parameterized macros Reduce code volume 09/02/11
  • 14. Step 8: Analysis 09/02/11 transfers immunocompromised state proc codes immunocompromised state diagnoses *For 11, also exclude anemia principal or secondary diagnoses *For 12, also exclude principal or secondary kidney disorder diagnoses include discharges with principal diagnosis code specified: bacterial pneumonia UTI 11,12 transfers cardiac procedure codes in any field *For 7 only, also exclude kidney disease diagnoses if accompanied by hemodialysis procs include discharges with principal diagnosis code specified: hypertension CHF angina 7*,8,13 transfers include discharges with principal diagnosis code specified: diabetes short term complications diabetes long term complications hypovolemia uncontrolled diabetes 1,3,10,14 Exclusions Numerator Measure
  • 15. Step 8: Parameterized Macro 09/02/11 %macro transfer(filename=)/STORE SOURCE; /*identify and delete transfers from numerator*/ CREATE TABLE &filename._TRANS AS SELECT B.conf_id, B.admit_dt, A.disch_dt FROM PQI.&filename A JOIN PQI.&filename B ON A.rhmo=B.rhmo AND A.bkey=B.bkey AND A.disch_dt BETWEEN B.admit_dt AND intnx('DAY',B.admit_dt,-1)/*re-admitted within 24 hours of discharge date*/ WHERE A.conf_id <> B.conf_id AND A.src_sys_prov_id <> B.src_sys_prov_id /*transferred from different facility*/ ; DELETE FROM PQI.&filename WHERE conf_ID IN (SELECT conf_id FROM &filename._TRANS) ; %mend transfer;
  • 16. Step 8: Putting it Together 09/02/11
  • 17. Steps 9-10: Documentation Comment code Use program headers Program name Developer name Date created Purpose Update information Programmer name Date modified Reason for modification Input/output tables 09/02/11
  • 18. Conclusion Break up large processes into smaller steps Number programs in order of process flow Create initial setup program Create final cleanup program Use macro variables for date selection criteria Use macro variables for file names Use macro variables for long lists that need frequent updating and/or are referenced frequently Use parameterized macros for similar processes Document using comments Document using program headers 09/02/11
  • 19. References SAS Institute Inc. 2009 . SAS 9.2 Macro Language Reference . Cary, NC: SAS Institute, Inc. Patridge, C. Best Practices: Using SAS Effectively/Efficiently . HASUG presentation 2/24/2011. Rhodes, D. If You Have Programming Standards, Please Raise Your Hand: An Everyman’s Guide . http://www.nesug.org/Proceedings/nesug10/ma/ma10.pdf (5/31/2011). 09/02/11
  • 20. Acknowledgement SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Other brand and product names are registered trademarks or trademarks of their respective companies. 09/02/11