DATA Step, Macro, Functions and more

Selecting when criteria is met within a smaller time period

Reply
New Contributor
Posts: 2

Selecting when criteria is met within a smaller time period

I have data for one year that includes one date variable. There are many rows per individual. I need to be able to select individuals who satisfy three criteria within any 90 day period in the year. The dates are not equally spaced or the same for every individual. Any help would be greatly appreciated. This needs to be able to done in proc sql.

Super Contributor
Posts: 578

Re: Selecting when criteria is met within a smaller time period

Posted in reply to kwokramer

off the cuff...

proc sql;

select

t1.individual,

t1.datevar,

count(*) as Occurrences

from

     have t1

     inner join have t2

          on t1.individual = t2.individual

               and intck('day',t1.datevar, t2.datevar) <=90

group by t1.individual, t1.datevar

having count(*)>=3;

quit;

Super User
Posts: 5,497

Re: Selecting when criteria is met within a smaller time period

One pitfall to code around ...

INTCK will return a negative number when the first date is later than the second date.  You probably don't want all of those included in your count.

New Contributor
Posts: 2

Re: Selecting when criteria is met within a smaller time period

Posted in reply to Astounding

Would sorting after the initial data pull fix that?

Super Contributor
Posts: 578

Re: Selecting when criteria is met within a smaller time period

Posted in reply to kwokramer

sorting wouldn't help.

proc sql;

select

t1.individual,

t1.datevar,

count(*) as Occurrences

from

     have t1

     inner join have t2

          on t1.individual = t2.individual

               and intck('day',t1.datevar, t2.datevar) <=90

               and t2.datevar >= t1.datevar

group by t1.individual, t1.datevar

having count(*)>=3;

quit;

Ask a Question
Discussion stats
  • 4 replies
  • 219 views
  • 6 likes
  • 3 in conversation