BookmarkSubscribeRSS Feed
a_zacMD
Obsidian | Level 7

I want to be able to flag those individuals who have multiple encounters and a previous encounter falls within a certain group, but only if it happens within a specified time frame (I am able to calculate the time, I'm just trying to illustrate the relationship.)

 

Here is an example. For ID 1234 there are two encounters, where the first is a type 1 and the second encounter happened at day 7. How can I loop the second encounter back to the previous (7-Jul-2020) encounter to confirm that encounter is a type 1 and therefore should fall into the bucket?

 

I don't care about ID 5656 because none of them fall into type 1. 

 

IDDateTypedeltaBucket
12347-Jul-201  
123414-Jul-20071
56567-Jul-200  
565614-Jul-2007 
88797-Jul-200  
887914-Jul-2017 
887921-Jul-20071

 

Thank you in advance, 

1 REPLY 1
PeterClemmensen
Tourmaline | Level 20

I think this is what you want

 

data have;
input ID Date $ Type delta Bucket;
infile datalines missover;
datalines;
1234 7-Jul-20  1    
1234 14-Jul-20 0 7 1
5656 7-Jul-20  0    
5656 14-Jul-20 0 7  
8879 7-Jul-20  0    
8879 14-Jul-20 1 7  
8879 21-Jul-20 0 7 1
;

data want;
   do until (last.id);
      set have;
      by id;
      if Type = 1 then flag = 1;
   end; 
   do until (last.id);
      set have;
      by id;
      output;
   end;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1 reply
  • 263 views
  • 0 likes
  • 2 in conversation