Presentation is loading. Please wait.

Presentation is loading. Please wait.

When “ANYDATE” Doesn’t Mean Any Date: A Macro Solution Charlotte King, Alberta Health Services John Fleming, Alberta Health Services SAS Global Forum Paper.

Similar presentations


Presentation on theme: "When “ANYDATE” Doesn’t Mean Any Date: A Macro Solution Charlotte King, Alberta Health Services John Fleming, Alberta Health Services SAS Global Forum Paper."— Presentation transcript:

1 When “ANYDATE” Doesn’t Mean Any Date: A Macro Solution Charlotte King, Alberta Health Services John Fleming, Alberta Health Services SAS Global Forum Paper Edmonton SAS User Group May 11, 2011

2 Problem

3 Macro %macro dates(inds, outds, messy, clean, year_start, missing_year_start_date, missing_year, dstyle); /* MACRO Part 1 SAS Code Here */ /* MACRO Part 2 SAS Code Here */ /* MACRO Part 3 SAS Code Here */ %mend dates;

4 Macro %macro dates(inds, outds, messy, clean, year_start, missing_year_start_date, missing_year, dstyle); /* MACRO Part 1 SAS Code Here */ /* MACRO Part 2 SAS Code Here */ /* MACRO Part 3 SAS Code Here */ %mend dates; Input And Output Data Sets

5 Macro %macro dates(inds, outds, messy, clean, year_start, missing_year_start_date, missing_year, dstyle); /* MACRO Part 1 SAS Code Here */ /* MACRO Part 2 SAS Code Here */ /* MACRO Part 3 SAS Code Here */ %mend dates; Dirty And Cleaned Date Variables

6 Macro %macro dates(inds, outds, messy, clean, year_start, missing_year_start_date, missing_year, dstyle); /* MACRO Part 1 SAS Code Here */ /* MACRO Part 2 SAS Code Here */ /* MACRO Part 3 SAS Code Here */ %mend dates; Date Parameters

7 Macro %macro dates(inds, outds, messy, clean, year_start, missing_year_start_date, missing_year, dstyle); /* MACRO Part 1 SAS Code Here */ /* MACRO Part 2 SAS Code Here */ /* MACRO Part 3 SAS Code Here */ %mend dates; Date Style Option

8 Ambiguous Dates How Do We Read This Date? 01/02/03 January 2, 2003? January 3, 2002? February 3, 2001? March 2, 2001? February 1, 2003? March 1, 2002? (MDY) (MYD) (YMD) (YDM) (DMY) (DYM) Which Of These Is It?

9 Ambiguous Dates options datestyle = mdy|myd|ymd|ydm|dmy|dym|locale;

10 Macro Part 1 data _null_; year_end = &year_start + 99; call symput('year_end',year_end); missing_year_end = mdy(month("&missing_year_start_date"d), day("&missing_year_start_date"d), year("&missing_year_start_date"d + 99)); call symput('missing_year_end_date',missing_year_end); run;

11 Macro Part 2 libname dateform "T:\date macro "; options yearcutoff = &year_start fmtsearch = (dateform) datestyle = &dstyle; %include "T:\date macro\date formats.sas";

12 Custom Informats proc format; picture mondyyyy (default=11) other ='%b %d %Y' (datatype=date); run; data infmt3; retain fmtname "mondyyyy" type "I"; do label = "1jan1900"d to "31dec2025"d; start = put (label,mondyyyy.); start = trim ( left (start) ); start=compress(compress(lowcase(start),,'s'),,'p'); output; end; hlo='O'; label=.; start=' '; output; run; proc format cntlin=infmt3; run;

13 Custom Informats proc format; picture mondyyyy (default=11) other ='%b %d %Y' (datatype=date); run; data infmt3; retain fmtname "mondyyyy" type "I"; do label = "1jan1900"d to "31dec2025"d; start = put (label,mondyyyy.); start = trim ( left (start) ); start=compress(compress(lowcase(start),,'s'),,'p'); output; end; hlo='O'; label=.; start=' '; output; run; proc format cntlin=infmt3; run;

14 Custom Informats proc format; picture mondyyyy (default=11) other ='%b %d %Y' (datatype=date); run; data infmt3; retain fmtname "mondyyyy" type "I"; do label = "1jan1900"d to "31dec2025"d; start = put (label,mondyyyy.); start = trim ( left (start) ); start=compress(compress(lowcase(start),,'s'),,'p'); output; end; hlo='O'; label=.; start=' '; output; run; proc format cntlin=infmt3; run;

15 Custom Informats proc format; picture mondyyyy (default=11) other ='%b %d %Y' (datatype=date); run; data infmt3; retain fmtname "mondyyyy" type "I"; do label = "1jan1900"d to "31dec2025"d; start = put (label,mondyyyy.); start = trim ( left (start) ); start=compress(compress(lowcase(start),,'s'),,'p'); output; end; hlo='O'; label=.; start=' '; output; run; proc format cntlin=infmt3; run;

16 Custom Informats proc format; picture mondyyyy (default=11) other ='%b %d %Y' (datatype=date); run; data infmt3; retain fmtname "mondyyyy" type "I"; do label = "1jan1900"d to "31dec2025"d; start = put (label,mondyyyy.); start = trim ( left (start) ); start=compress(compress(lowcase(start),,'s'),,'p'); output; end; hlo='O'; label=.; start=' '; output; run; proc format cntlin=infmt3; run;

17 Macro Part 3 data &outds; set &inds; &messy = compress(compress(lowcase(&messy),,'s'),,'p');

18 &clean=input(&messy, worddate.); if missing(&clean) then &clean=input(&messy, anydtdte.); if missing(&clean) then &clean=input(&messy, worddatx.); if missing(&clean) then &clean=input(lowcase(&messy), mondyyyy.); if missing(&clean) then &clean=input(&messy, mondyy.); if missing(&clean) then &clean=input(&messy, monddyyyy.); if missing(&clean) then &clean=input(&messy, monddyy.); if missing(&clean) then &clean=input(&messy, ddmon.); if missing(&clean) then &clean=input(&messy, dmon.); if missing(&clean) then &clean=input(&messy, montddyy.); if missing(&clean) then &clean=input(&messy, montdyy.); format &clean date9.; run; %mend dates; Macro Part 3

19 Summary Parameters dsin, dsout, messy, clean year_start, missing_year_start_date missing_year dstyle Robust and Expandable Future Versions

20 Contact Information Charlotte King John Fleming Community Oncology Alberta Health Services – Cancer Care


Download ppt "When “ANYDATE” Doesn’t Mean Any Date: A Macro Solution Charlotte King, Alberta Health Services John Fleming, Alberta Health Services SAS Global Forum Paper."

Similar presentations


Ads by Google