BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
noda6003
Quartz | Level 8

 

I need to create a flag defining whether an incident has started within the first 24 hours of the sdate.

 

something like below

any help on how to do it

 

sdate                       incident                     flag

04DEC2018         05DEC2018                  Y

08JAN2018          03JAN2018                  N

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

With datetimes:

data have;
input sdate :e8601dt19. incident :e8601dt19.;
format sdate incident e8601dt19.;
cards;
2018-12-04T10:03 2018-12-05T09:03
2018-01-08T13:03 2018-01-03T10:03
;
run;

data want;
set have;
flag = ifc(0 <= intck('dtday',sdate,incident,'c') <= 1,'Y','N');
run;

proc print data=want noobs;
run;

Result:

sdate                  incident               flag

2018-12-04T10:03:00    2018-12-05T09:03:00     Y  
2018-01-08T13:03:00    2018-01-03T10:03:00     N  

View solution in original post

7 REPLIES 7
noda6003
Quartz | Level 8

i have both date and datetime variables, datetime is character variable something like "2018-12-05T12:00" .

 

datetime makes sense to calculate flag if i am not wrong.

noda6003
Quartz | Level 8

sorry if it is datetime like below than how to do?

 

sdate                                  incident                                 flag

04DEC2018T10:03         05DEC2018T09:03                   Y

08JAN2018T13:03          03JAN2018T10:03                   N

ChrisNZ
Tourmaline | Level 20

If you don't consider the time:

FLAG = ifc(-1 <= (input(SDATE,date9.) - input(INCIDENT,date9.)) <= 1, 'Y', 'N');

noda6003
Quartz | Level 8

i want to consider time, can i do something like this?

FLAG = ifc(-1 <= (SDATE- INCIDENT) <= 1, 'Y', 'N');

Kurt_Bremser
Super User

With datetimes:

data have;
input sdate :e8601dt19. incident :e8601dt19.;
format sdate incident e8601dt19.;
cards;
2018-12-04T10:03 2018-12-05T09:03
2018-01-08T13:03 2018-01-03T10:03
;
run;

data want;
set have;
flag = ifc(0 <= intck('dtday',sdate,incident,'c') <= 1,'Y','N');
run;

proc print data=want noobs;
run;

Result:

sdate                  incident               flag

2018-12-04T10:03:00    2018-12-05T09:03:00     Y  
2018-01-08T13:03:00    2018-01-03T10:03:00     N  

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 956 views
  • 1 like
  • 4 in conversation