Difference Between two dates for all the varaiable in dataset

Reply
Contributor
Posts: 32

Difference Between two dates for all the varaiable in dataset

data ftu;

set  FILET.Aedata;

RFSTDTC =input ( RFSTDTC  ,YYMMDD10.);

run;

%let A = RFSTDTC;

%let keepvar = AESTDT AEENDT RFSTDTC;

data ftgu;

set ftu ;

do until

NumDays = intck( 'day',&A,DT  );

run;

Attachment
Esteemed Advisor
Esteemed Advisor
Posts: 7,249

Re: Difference Between two dates for all the varaiable in dataset

So what is the question?  There is another option in the intck - discrete or continuous, not sure if that is what you mean.  If you are just dealing with dates however, which are days since a certain date, then you can just do latest_date - first_date = number of days (you may need to add 1 depending on inclusion of base or not).

Esteemed Advisor
Posts: 6,698

Re: Difference Between two dates for all the varaiable in dataset

Your code is bogus:

RFSTDTC =input ( RFSTDTC  ,YYMMDD10.);

will cause problems.

By definition, the input(...yymmdd10.) needs a character value as input and delivers a numerical value.

SAS will do a lot of the conversions for you, but dirty programming like that will come back to hit you on the head, sooner or later.

data ftgu;

set ftu ;

do until

NumDays = intck( 'day',&A,DT  );

run;

is syntactically wrong and will not compile; the do loop misses an end_statement.

If it compiled after the end is added, it would do nothing, or run indefinitely in an infinite loop, because the condition will not change at all.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Super User
Posts: 6,368

Re: Difference Between two dates for all the varaiable in dataset

What is the question?  You posted a dataset with 3 variables.  2 are numeric with a date format attached (YYMMDD10.) and the third is character with values that look like they were generated with the same format.

What does the subject of your post mean? "Difference Between two dates for all the varaiable in dataset"

From the pseudo code you posted perhaps you want to

1) convert the character variable to a date.

2) calculate the difference between it and all of the other date variables in the dataset.

data want ;

set aedata ;

RFSTDT =input ( RFSTDTC , YYMMDD10.);

format RFSTDT yymmdd10. ;

study_day = aestdt - rfstdt + 1;

aedur = aeendt - aestdt + 1 ;

run;

Grand Advisor
Posts: 9,593

Re: Difference Between two dates for all the varaiable in dataset

Are you doing some CDISC about AE ?

You'd better post the sample data , not attachment . And more important the output you need .

Xia Keshan

Ask a Question
Discussion stats
  • 4 replies
  • 314 views
  • 1 like
  • 5 in conversation