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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 3304 views
  • 0 likes
  • 2 in conversation