Hi Everyone!
For my study, I want to retrieve records from all phases when one hour prior to first visit time i.e. visit_F ({HH:MM}-1) is greater than last visit time (HH:MM)
In database, all dates are stored in character format.
data visit;
input phase visit_F $20. visit_E $20.;
cards;
1 2012-04-24T19:22:03 2012-04-24T20:23:03
2 2012-04-22T07:22:03 2012-04-22T07:22:01
3 2012-04-24T19:22:03 2012-04-24T16:23:03
;
run;
As @Kurt_Bremser remarked, you should change the data to numeric datetimes, if possible. If not, you will have to do the conversion on the fly, e.g.:
data want;
set visit;
dt_first=input(visit_f,e8601dt.);
dt_last=input(visit_e,e8601dt.);
format dt_: datetime22.;
if dt_first-3600>dt_last;
run;
The 3600 is (of course) the number of seconds in an hour, SAS datetime values are recorded as the number of seconds since January first, 1960.
Dates or times in character format are USELESS. Convert them in the database before doing anything else.
What should be the result of your data?
As @Kurt_Bremser remarked, you should change the data to numeric datetimes, if possible. If not, you will have to do the conversion on the fly, e.g.:
data want;
set visit;
dt_first=input(visit_f,e8601dt.);
dt_last=input(visit_e,e8601dt.);
format dt_: datetime22.;
if dt_first-3600>dt_last;
run;
The 3600 is (of course) the number of seconds in an hour, SAS datetime values are recorded as the number of seconds since January first, 1960.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: