LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2009, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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.
Comments: To: "ya.huang@AMYLIN.COM" <ya.huang@AMYLIN.COM>
In-Reply-To:  <200907301729.n6UHL6l2002555@malibu.cc.uga.edu>
Content-Type: text/plain; charset="us-ascii"

/*

Ya wrote:

----- Original Message ----- From: "Ya Huang" <ya.huang@AMYLIN.COM> To: <SAS-L@LISTSERV.UGA.EDU> 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. > > Thanks > > Ya >

Hi Ya,

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.

HTH?

Cheers,

John Hixon jhixon@amgen.com

*/ data junk; 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; DateTimeC=put(year,z4.)||"-"||put(month,z2.)||"-"||put(day,z2.)||"T"||put(hour,z2.)||":"||put(minute,z2.)||":"||put(second,z2.); DateTimeN=input(DateTimeC,is8601dt.); DateTimeN_withFormat=DateTimeN; output; end; end; end; end; end; end; run; proc print data=junk; format dateTimeN_withFormat is8601dt.; run;


Back to: Top of message | Previous page | Main SAS-L page