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

Hello,

I am trying to calculate the date difference between 31dec16 and the variable service_dte (which is the start date when an employee joined the company). the format of the variable service_dte is datetime16. and according to SAS it is in numeric value.How should I proceed? since service_dte and '31dec16' are of different format, I tried to convert the format fist, but it is not working. I am currently using SAS 9.4.

this is what i tried:

 

data trial;

set lwop.data2016;

service_date=input(service_dte,datetime16.);

format service_date date.;

run;

 

i got the following error message:

Note: invalid argument to function input at line 3815 column. warning:limit set by errors=option reached. further errors of this type will not be printed. 


 Thank you very much for your help!!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Formats just tell SAS how to display the values. If that variable really contains numbers that are valid datetime values (number of seconds) then to calculate the difference in DAYS you will need to convert the number of seconds into number of days.  Essentially you just need to divide by the number of seconds in a day, but there is a built in function to make it easier (and clearer).

data trial;
  set lwop.data2016;
  service_date=datepart(service_dte);
  format service_date date9.;
run;

Once you have two date values (number of days) then to find a difference just subtract them.

 

PS Make sure to always display dates with 4 digits for the year to avoid confusion.

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Formats just tell SAS how to display the values. If that variable really contains numbers that are valid datetime values (number of seconds) then to calculate the difference in DAYS you will need to convert the number of seconds into number of days.  Essentially you just need to divide by the number of seconds in a day, but there is a built in function to make it easier (and clearer).

data trial;
  set lwop.data2016;
  service_date=datepart(service_dte);
  format service_date date9.;
run;

Once you have two date values (number of days) then to find a difference just subtract them.

 

PS Make sure to always display dates with 4 digits for the year to avoid confusion.

carinetang
Calcite | Level 5
Thank you very much for the explanation! The substraction did work!

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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
  • 2 replies
  • 1359 views
  • 1 like
  • 2 in conversation