BookmarkSubscribeRSS Feed
kwokramer
Calcite | Level 5

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.

4 REPLIES 4
DBailey
Lapis Lazuli | Level 10

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;

Astounding
PROC Star

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.

kwokramer
Calcite | Level 5

Would sorting after the initial data pull fix that?

DBailey
Lapis Lazuli | Level 10

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;

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
  • 4 replies
  • 814 views
  • 6 likes
  • 3 in conversation