Solved
New Contributor
Posts: 2

comparison of three dates

Hello, I have a problem with the dates on SAS.

I have two dates DATE A and DATE B in format  DDMMYYS10. and I must write:

first (DATE A) between (DATE B) and (DATE B + 10 DAYS).

The Dates do not know them, are generic.

As I write this in SAS language?

Thanks

Accepted Solutions
Solution
‎05-22-2013 10:21 PM
Posts: 4,736

Re: comparison of three dates

The code you've provided doesn't really show how the data is structured so it's still guesswork for us (that's why I've asked for a data step creating some sample data).

By looking at your code and guessing what you might want to achieve:

data temp;
set conti2;
by num_contratto date_operation;
retain R_date_operation;

if first.num_contratto then R_date_operation = date_operation;

days = abs (intck ('day', R_date_operation, date_opening));

if days <= 10 then flag = 'yes'  ;  /* the error was thrown because the ';' was missing */

else flag = 'no';

run;

All Replies
Posts: 4,736

Re: comparison of three dates

SAS dates (as numeric values) are the number of days since 1/1/1960. So what you need to do is compare numbers.

A format of DDMMYYS10. is only an instruction for SAS of how to print numbers.

if Date_B <= Date_A <= (Date_B+10) then put 'Date A in range';

You will get a more specific answer if you can provide some sample data (a data step creating this sample data) and then tell us how the result should look like?

New Contributor
Posts: 2

Re: comparison of three dates

I have writed:

data temp;

set conti2;

by num_contratto;

retain date_operation;      /* this is wrong... */

if first.date_operation then first = date_operation;     /* I think this is wrong, I would the first date of date-operation */

run;

data contid;

set temp;

by num_contratto;

days = abs (intck ('day', date_operation, date_opening));  /* calculates the difference between the two dates */

run;

data contie;

set contid;

by num_contratto;

if days <= 10 then flag = 'yes'         /* this is wrong ERROR 180-322: Statement is not valid or it is used out of proper order. */

else flag = 'no';

run;

the difference of date_opening and date_operation must be <= 10 days.

Can you help me?

Thanks

Solution
‎05-22-2013 10:21 PM
Posts: 4,736

Re: comparison of three dates

The code you've provided doesn't really show how the data is structured so it's still guesswork for us (that's why I've asked for a data step creating some sample data).

By looking at your code and guessing what you might want to achieve:

data temp;
set conti2;
by num_contratto date_operation;
retain R_date_operation;

if first.num_contratto then R_date_operation = date_operation;

days = abs (intck ('day', R_date_operation, date_opening));

if days <= 10 then flag = 'yes'  ;  /* the error was thrown because the ';' was missing */

else flag = 'no';

run;

🔒 This topic is solved and locked.