Date: Thu, 30 Jul 2009 15:55:51 -0400
Reply-To: "Hixon, John" <jhixon@AMGEN.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Hixon, John" <jhixon@AMGEN.COM>
Subject: SAS DateTime Format that sorts correctly is IS8601dt.
Content-Type: text/plain; charset="us-ascii"
----- Original Message -----
From: "Ya Huang" <ya.huang@AMYLIN.COM>
Sent: Thursday, July 30, 2009 11:33
Subject: consistency of sorting a date or time var in num and char
> Hi there,
> Obviously sorting a date var as numeric is different from a date9.
> formatted character, since '03JAN2009' is ordered after '03APR2009'.
> But '03JAN2009'DT should have the same order as '01032009'. For time
> var, a time5. formatted string will not have the same order as the
> underline numeric var, since time5. is not zero padded.
> I wonder what kind of formatted date, time or datetime var have
> the same order as the underline numeric var.
The formats you aree looking for are the IS8601 formats.
For DateTime the format is is8601dt.
For date: is8601da.
For Time: is8601tm.;
See example below for DateTime.
do year=1950 to 2025 by 25;
do month=1 to 12 by 4;
do day=5 to 30 by 5;
do hour=1 to 23 by 11;
do minute=1 to 59 by 29;
do second=1 to 59 by 29;
end; end; end; end; end; end;
proc print data=junk;
format dateTimeN_withFormat is8601dt.;