BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
abraham1
Obsidian | Level 7

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;
1 ACCEPTED SOLUTION

Accepted Solutions
s_lassen
Meteorite | Level 14

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.

View solution in original post

2 REPLIES 2
s_lassen
Meteorite | Level 14

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 248 views
  • 1 like
  • 3 in conversation