Friday, July 16, 2010

Got dating problems? Use ANYDATE...

Many a times we might come across a situation where we would not be able to determine the informat of the date or datetime variable that needs to be read into the SAS dataset. Or me may at times fail to remember the informat name for a particular date informat.

To address these problems, SAS has come up with a common informat for reading the dates for all types of formats - ANYDTDTEw.

See the example below:

Data dates;
Input cdate $22.;
Cards;
16-apr-07
01-02-07
2007-05-06
02-jun-07
13-sep-2007
01JAN2009 14:30:08.5
;
Run;


/* Convert them to required date format using AnydtdteW */

Data Convert;
Set dates;
Date = Input (cdate, ANYDTDTE21.);
Format date date9.;
Run;

The contents of the dataset would be as shown below:

16APR2007
02JAN2007
06MAY2007
02JUN2007
13SEP2007
01JAN2009

However, if we were to have a date being represented as "02/03/04", then it could be quite confusion for us as well as the SAS compiler to know the exact date informat that is to be read in. To overcome this problem, we use the SAS System option - datestyle.

The possible set of values for the datestyle option are: MDY MYD YMD YDM DMY DYM LOCALE.

See the below example to understand the datestyle option clearly:

option datestyle=dmy;

data test;
format dt date9.;
input dt anydtdte10.;
cards;
02/03/04
;
run;

/*output = 02MAR2004 */

option datestyle=ymd;

data test;
format dt date9.;
input dt anydtdte10.;
cards;
02/03/04
;
run;

/* output = 04MAR2002 */

option datestyle=myd;

data test;
format dt date9.;
input dt anydtdte10.;
cards;
02/03/04
;
run;

/* output = 04FEB2003 */

1 comment:

  1. MatesCity.com - New Dating site

    MatesCity is new dating site where you can find friends or partner.

    http://matescity.com

    ReplyDelete