Help using Base SAS procedures

Custom Intervals using INTCK function not providing rights results using Datetime

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

Custom Intervals using INTCK function not providing rights results using Datetime

Hi Everyone,

 

I am relatelvely new programming in SAS and I've been stuck for days (I've tried all the sources in SAS and tested every suggestion in the web) with the following problem;

 

A) I am tryng to calculate the duration between two dates (DATETIME19.) .

B) I am using Custom Intervals so I have theINTERVALDS below defined in SAS;

         1)options intervalds=(heuresOuvrables=Commun.heures_ouvrables);

C) The option above allows me to defined "bounderies" which are explained here http://support.sas.com/documentation/cdl/en/etsug/63939/HTML/default/viewer.htm#etsug_intervals_sect...

D) After runing the following code, the results that I obtained for the calculation let's say for example between  07FEB2017:15:32:00 and  08FEB2017:08:00:00 is age_heures = 2hours but in reality as a defined bounderies it should only count for 58minutes, so it should be age_heures = 0. (opining hours are 8am to 4:30 pm, Monday to Friday) .

 

Here is the code;

 

Data Escalades_30(DROP= newimp newdebutheure) ;
	set Escalades_2;
	newimp = datepart(D_but_d_imputabilit_);
	newdebutheure = datepart(Heure_d_ouverture);
	If D_but_d_imputabilit_ < Heure_d_ouverture then
	  age_heures = intck("heuresOuvrables", D_but_d_imputabilit_, Heure_d_ouverture,'d');
	If age_heures = 1 then;
	  age_minutes = intck('minute', D_but_d_imputabilit_, Heure_d_ouverture);	

	If Heure_d_ouverture < D_but_d_imputabilit_ then do Delai_prise_en_charge = 99;
	end;
	else If age_heures < 1 then do Delai_prise_en_charge = 0; 
	end;
	else do  Delai_prise_en_charge = 1;
	end;
	If age_minutes ne "." and age_minutes < 59 then do Delai_prise_en_charge = 0; 
	end;
	volume = 1;
 run;

I've tried using 'Discrete' method but it gives me the same result.

 

Could you plesase guide me for resulving this issue.

 

I would apprecaite it any feedback.

 

Assis Jadue

Version: SAS 9.3 for Windows


Accepted Solutions
Solution
‎04-05-2017 12:46 PM
Super User
Posts: 10,500

Re: Custom Intervals using INTCK function not providing rights results using Datetime

I believe you would have to have no interval, with both values in the begin and end interval for one record to get 0. If you are trying to do something the orginal data set wasn't intended for you may need to create and specify a different dataset.

 

Are you trying to get the actual number of minutes the second value is past the end of the interval range the first value is in?

If that is the case then you may just want the INTCH value of 'minutes' but use the incremented value of the first to the end of the interval.

 

This is a guess but I might try something like this

age_minutes = intck('minute', intnx('heuresOuvrables ',D_but_d_imputabilit_,0,'e'), Heure_d_ouverture);

 

which, if it works, advance the first value to the end of the interval in intervalds set before determinng the number of minutes.

Maybe. You may need to do something similar for the hours.

 

 

View solution in original post


All Replies
Super User
Posts: 10,500

Re: Custom Intervals using INTCK function not providing rights results using Datetime

You would have to provide the values in the Intervalds data set to let us diagnose issues.

 

You can post a data step to build your data set using Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

Occasional Contributor
Posts: 8

Re: Custom Intervals using INTCK function not providing rights results using Datetime

Thanks ballardw,  Here is the code using the dta step macro;

 

data WORK.ESCALADES_2;
  infile datalines dsd truncover;
  input Incident_ID:$11. Fournisseur:$5. Title:$87. D_lai_de_prise_en_charge_Heures_:32. Heure_d_ouverture:DATETIME19. D_but_d_imputabilit_:DATETIME19. Fin_d_imputabilit_:DATETIME19.;
datalines4;
INC00906695,GDIEG,GDI - Escalade de gestion pour un incident - Client impacté: chantal Desroches,8.5,01FEB2017:12:03:26,01FEB2017:12:03:48,
INC00910244,GDIEG,GDI - Escalade de gestion pour un incident - Client impacté: Lucie Lemieux,8.5,07FEB2017:11:25:32,07FEB2017:10:29:01,
INC00910812,GDIEG,GDI - Escalade de gestion pour un incident - Client impacté: Julie Ricard,0,08FEB2017:08:00:00,07FEB2017:15:32:00,
INC00911295,GDIEG,GDI - Escalade de gestion pour un incident - Client impacté:Marie-Josee Boucher,8.5,08FEB2017:14:12:44,08FEB2017:13:52:31,
INC00912492,GDIEG,GDI - Escalade de gestion pour un incident - Client impacté: Jocelyne Fillion,8.5,10FEB2017:08:43:14,10FEB2017:08:41:31,
;;;;
Occasional Contributor
Posts: 8

Re: Custom Intervals using INTCK function not providing rights results using Datetime

Forgot the excel file with Intervalds...Thanks.

Super User
Posts: 10,500

Re: Custom Intervals using INTCK function not providing rights results using Datetime

I believe you are getting 2 as the inteval count because there are two records between the values you show for your example in the intervalds data set.

Occasional Contributor
Posts: 8

Re: Custom Intervals using INTCK function not providing rights results using Datetime

Thanks for the answer, now I undertand the interval it counts 2 because it has two records between the values. I modified instervalds data set to have only 1 interval between 08:00:00 and 16:30:00. The only problem is that still get one hour instead of 58 minutes in my result, when comparing the two dates. Could I use 'Minute' as an optional shift index mixing with the intervalds data set? 

Solution
‎04-05-2017 12:46 PM
Super User
Posts: 10,500

Re: Custom Intervals using INTCK function not providing rights results using Datetime

I believe you would have to have no interval, with both values in the begin and end interval for one record to get 0. If you are trying to do something the orginal data set wasn't intended for you may need to create and specify a different dataset.

 

Are you trying to get the actual number of minutes the second value is past the end of the interval range the first value is in?

If that is the case then you may just want the INTCH value of 'minutes' but use the incremented value of the first to the end of the interval.

 

This is a guess but I might try something like this

age_minutes = intck('minute', intnx('heuresOuvrables ',D_but_d_imputabilit_,0,'e'), Heure_d_ouverture);

 

which, if it works, advance the first value to the end of the interval in intervalds set before determinng the number of minutes.

Maybe. You may need to do something similar for the hours.

 

 

Occasional Contributor
Posts: 8

Re: Custom Intervals using INTCK function not providing rights results using Datetime

Thanks ballardw, as you mentioned I was looking "to get the actual number of minutes the second value is past the end of the interval range the first value is in". 

I figured it out using your suggestion regarding minutes advancing the first value to the end of the interval in intervalds

I only twisted with some binary calculation to get my pass and fails but somehow you helped to get me back in my code but with differents eyes.

Have a great one !

Assis Jadue

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 138 views
  • 1 like
  • 2 in conversation