BookmarkSubscribeRSS Feed
CV9
Calcite | Level 5 CV9
Calcite | Level 5

Hello!

I am seeking some assistance with the best formatting for date/time in SAS University Edition and with code to calculate time intervals between 2 date/times.

 

I have data with initial enrolment dates for people in a study, and then dates for tests.  These are currently in Excel in a variety of date formats, e.g.,

dd-mm-yyyy and separately 00:00

dd/mm/yyyy and separately 00:00

yyyy-mm-dd 00:00

Sep dd yyyy 00:00:00

yyyy-mm-dd and separately 00:00:00

 

I want to reformat all of the dates so they are consistent.  On searching SAS help online, it seems as though reformatting to 17MAR00:00:00:00 is appropriate, and I have started to attempt to do this manually.  I am wondering if anyone can confirm that this is the best way to reformat for SAS University Edition?

 

Also, I would like to then calculate the time in minutes between 2 dates.  From what I have read it appears that the INTCK function is appropriate for this, but it did not seem to work in SAS UE.  I am not sure if it was just the way I wrote the code.  

 

I did the following:

 

data xxtest2;
set xxtest;
by SPCODE;
days=intck('dtminute', ADM_DT, COL_DT);
put minutes=;

run;

 

 

Many thanks in advance for any assistance with this.

 

4 REPLIES 4
PGStats
Opal | Level 21

if ADM_DT and COL_DT are true SAS datetimes of SAS times, intck should word when you replace "dtminute" with "minute".

PG
CV9
Calcite | Level 5 CV9
Calcite | Level 5

Many thanks for your reply!  Unfortunately I still could not get it to work in SAS.  I am not sure why.  For now, am calculating in Excel.

andreas_lds
Jade | Level 19

@CV9 wrote:

Many thanks for your reply!  Unfortunately I still could not get it to work in SAS.  I am not sure why.  For now, am calculating in Excel.


 

"I still could not get it to work in SAS" is so vague, that it is hardly possible to tell how to fix the problem. If you want more help, please post (an extract) of your data in usable form. How to convert datasets to data steps explains how to do it.

Satish_Parida
Lapis Lazuli | Level 10

I am guessing you want this.

 

data have;
input date1:ddmmyy10. time1:time5. date2:ddmmyy10. time2:time5.;
format datetime1 datetime20. datetime2 datetime20.;		/*Unifroning datetime */
datetime1=(date1*24*60*60)+time1;  /*Coverting Day to Time*/
datetime2=(date2*24*60*60)+time2;
difference=intck('minute',datetime1,datetime2,'C');
cards;
12-09-2018 00:00 19-10-2018 00:00
01-11-2018 10:00 20-12-2018 23:00
;
run;

Please let us know if it worked for you.

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 985 views
  • 0 likes
  • 4 in conversation