Tuesday, June 29, 2010

dhms function, case + if then else or when

Syntax

DHMS(date,hour,minute,second)

Arguments

date specifies a SAS expression that represents a SAS date value.

hour is numeric.

minute is numeric.

second is numeric.

Details

The DHMS function returns a numeric value that represents a SAS datetime value. This numeric value can be either positive or negative.

example:
dtid=dhms('01jan03'd,15,30,15);
put dtid;
put dtid datetime.;

result:
1357054215
01JAN03:15:30:15
01JAN03:15:30:15

CASE when then
when then
else
END

example:
data all;
input pat num date datetime19.;
cards;
12 1 27AUG2008:00:00:00
12 2 19SEP2008:00:00:00
12 3 12AUG2009:00:00:00
12 4 28AUG2009:00:00:00
12 5 09SEP2009:00:00:00
;
run;

proc print;
format date datetime19.;

proc sql;
create table aa as
select pat
,6 as ord
,min(case when num=4 and date ne . then dhms(mdy(month(datepart(date)),day(datepart(date)+7),year(datepart(date))),
23, 59, 00) else . end) as stdt format=datetime19.
,min(case when num=5 and date ne . then dhms(mdy(month(datepart(date)),day(datepart(date)+7),year(datepart(date))),
23, 59, 00) else . end) as spdt format=datetime19.
from all(where=(num in(4,5)))
group by pat
;
proc print data=aa;run;

No comments:

Post a Comment