BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi everyone,

This is my first post on this forum and I'd like to kindly ask you to assist me with this problem.

In Enterprise Guide I'm writing an SQL statement in which I wan't to (in the select part) get the difference in days between two date values. Both date values/columns are in yyyymmdd format. Unfortunatelly, the standard sql DATEDIFF function is not working here and I've tried DATDIF but with no luck.

It tried something like this:

PROC SQL;
CREATE TABLE EGTASK.MYQUERY
AS SELECT DATDIF (START_DATE, END_DATE, 'ACT/ACT'), ...
FROM TABLE1;
QUIT;


I'd appreciate your help very much 😞
2 REPLIES 2
JasonS_SAS
SAS Employee
If START_DATE and END_DATE are character values, those need to be converted to numeric SAS date values before calling DATDIF. One way to convert a character value to a numeric value is to use the INPUT function.

Here is a small program that uses the INPUT function and the YYMMDD. informat to convert character date values into numeric date values.

[pre]
data in;
start_date = '20100201'; end_date = '20100204'; output;
run;

proc sql;
create table out
as select
datdif(input(start_date, YYMMDD8.),
input(end_date, YYMMDD8.),
'ACT/ACT') as datdif,
start_date,
end_date
from in;
quit;
[/pre]
deleted_user
Not applicable
Thanks so much for your help, Jason! I appreciate it!

I did what u suggested and it works perfectly 🙂

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
  • 2 replies
  • 3560 views
  • 0 likes
  • 2 in conversation