Date: Fri, 2 Apr 2010 11:51:23 -0700
Reply-To: "Terjeson, Mark" <Mterjeson@RUSSELL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Terjeson, Mark" <Mterjeson@RUSSELL.COM>
Subject: Re: Sorting of dates with and without the time part
In-Reply-To: A<16FD64291482A34F995D2AF14A5C932C089B3DEB@MAIL002.prod.ds.russell.com>
Content-Type: text/plain; charset="us-ascii"
Whoops, my fingers typed gt instead of lt
if myvalue lt 999999 then
newvalueinseconds = myvalue*86400;
else
newvalueinseconds = myvalue;
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Terjeson, Mark
Sent: Friday, April 02, 2010 11:42 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Sorting of dates with and without the time part
Hi,
The SAS date is number of DAYS since Jan1,1960.
The SAS datetime is number of SECONDS since
Jan1,1960.
To have them sort you can either convert them
all to date(days), or you can convert them all
to datetime(seconds), then your sorting will
interleave as desired.
To convert SAS datetime(seconds) to date(days)
you can do this:
mydate = datepart(mydatetime);
To convert SAS date(days) to datetime(seconds)
you can do this:
mydatetime= mydate*86400;
i.e. 86400 is the number of seconds in a day.
(e.g. 24hrs*60min*60sec)
If for some uncommon situation that you have
a mixture of dates and datetime values in a
single variable, you can conditional fold them
all one direction by doing something like:
if myvalue lt 999999 then
newvalueinseconds = myvalue*86400;
else
newvalueinseconds = myvalue;
Then they will all be datetime in seconds.
Hope this is helpful.
Mark Terjeson
Investment Business Intelligence
Investment Management & Research
Russell Investments
253-439-2367
Russell
Global Leaders in Multi-Manager Investing
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
SAS_learner
Sent: Friday, April 02, 2010 11:27 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Sorting of dates with and without the time part
Hello all,
I have a dataset with Character dates some of them have time part and
some
of them do not. When I make those char dates as Numeric and sort them
the
dates with missing time part are coming up (giving me wrong sort order )
how
do I approach this problem
Here is example what I am talking
data test ;
a = 18176 ;
b = 1568895000 ;
Run;
Data test ;
set test ;
time = Put (b , Is8601dt. ) ;
time1 = Put (a , Is8601da. ) ;
run;
data test1 ;
a = 18176 ;
a = 1568895000 ;
Run;
*Sorting this dataset would give me 18176 first and 1568895000 last *;
Proc Sort data = test1 ;
By a ;
Run ;