SAS stores TIME values as number of seconds. So you can subtract to get the difference in seconds. You could use a TIME type format to display that. If you actually want to convert to a number of hours then just divide by the number of seconds in an hour.
If you only have time of day readings (and not full datetime readings) then you probably need to be sure they represent time from different days. If you can assume that none of the observations represent intervals longer than 24 hours that test is just whether the beginning time of day is before the ending time of day. If the wake time of day is less than the sleep time of day then that means they woke on the NEXT day. So you can take advantage of the fact that datetime values are also in stored in seconds and that SAS returns zero for FALSE boolean expressions and one for TRUE boolean expressions.
Example:
data have ;
input id sleep :time. wake :time. ;
format sleep wake tod8. ;
cards;
1 10:00pm 06:00am
2 03:00pm 11:00pm
3 11:00 11:00
;
proc print;
run;
data want;
set have;
seconds = dhms(wake<sleep,0,0,wake) - dhms(0,0,0,sleep) ;
hours = seconds/'01:00:00't ;
format seconds time12.;
run;
proc print;
run;
Results:
... View more