DATA Step, Macro, Functions and more

Please help - DATDIF with yyyymmdd problem

Reply
N/A
Posts: 0

Please help - DATDIF with yyyymmdd problem

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 Smiley Sad
SAS Employee
Posts: 39

Re: Please help - DATDIF with yyyymmdd problem

Posted in reply to deleted_user
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]
N/A
Posts: 0

Re: Please help - DATDIF with yyyymmdd problem

Posted in reply to JasonS_SAS
Thanks so much for your help, Jason! I appreciate it!

I did what u suggested and it works perfectly Smiley Happy
Ask a Question
Discussion stats
  • 2 replies
  • 1432 views
  • 0 likes
  • 2 in conversation