<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to enumerate dated events within x days of each other? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-enumerate-dated-events-within-x-days-of-each-other/m-p/919098#M362025</link>
    <description>&lt;P&gt;Brilliant, Ksharp!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I don't understand why the "want+1" works correctly if the "want" variable is not retained. I think (incorrectly?) that "want" will only have a value of 1 for first.ID and otherwise will be set to missing. So how does "want" equal 2 when the formula (in my mind) is "missing (.) + 1"? It seems like the value of "want" is being retained from the prior record but this variable has not been listed in the "retain" statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help me understand?&lt;/P&gt;</description>
    <pubDate>Wed, 06 Mar 2024 13:09:11 GMT</pubDate>
    <dc:creator>samp945</dc:creator>
    <dc:date>2024-03-06T13:09:11Z</dc:date>
    <item>
      <title>How to enumerate dated events within x days of each other?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-enumerate-dated-events-within-x-days-of-each-other/m-p/919025#M361990</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a large, long dataset with dated&amp;nbsp; events by ID number.&amp;nbsp; I'd like to create an enumeration variable for each event called Event_Number. However, I'd like the enumeration variable to group dates that are within 180 days of each other.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have struggled all day to try to figure out a way to do this with no luck. Any help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the sample data (code below) you can see that ID 01 has two events within 180 days, but they are currently numbered as two separate events. I'd like both events for ID 01 to be enumerated as the same event ("1").&lt;/P&gt;&lt;P&gt;The same issue occurs again for ID 22 for events 5 and 6. I'd like both events 5 and 6 to be counted as one event ("5").&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I read a &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_self"&gt;post on creating sample&lt;/A&gt; data but I'm not sure if I've done that correctly:&lt;/P&gt;&lt;PRE&gt;Create table events(ID varchar(6), date float, event_number float);&lt;BR /&gt;Insert into events(ID, date, event_number) Values('01', 05/11/1960, 1);&lt;BR /&gt;Insert into events(ID, date, event_number) Values('01', 06/30/1960, 2);&lt;BR /&gt;Insert into events(ID, date, event_number) Values('04', 07/31/1995, 1);&lt;BR /&gt;Insert into events(ID, date, event_number) Values('22', 11/26/1969, 1);&lt;BR /&gt;Insert into events(ID, date, event_number) Values('22', 07/06/1981, 2);&lt;BR /&gt;Insert into events(ID, date, event_number) Values('22', 07/14/1986, 3);&lt;BR /&gt;Insert into events(ID, date, event_number) Values('22', 03/25/1992, 4);&lt;BR /&gt;Insert into events(ID, date, event_number) Values('22', 03/25/1992, 4);&lt;BR /&gt;Insert into events(ID, date, event_number) Values('22', 09/02/1993, 5);&lt;BR /&gt;Insert into events(ID, date, event_number) Values('22', 09/15/1993, 6);&lt;/PRE&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2024 01:58:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-enumerate-dated-events-within-x-days-of-each-other/m-p/919025#M361990</guid>
      <dc:creator>samp945</dc:creator>
      <dc:date>2024-03-06T01:58:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to enumerate dated events within x days of each other?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-enumerate-dated-events-within-x-days-of-each-other/m-p/919027#M361992</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards dlm="',";
input ID $ date :mmddyy12. event_number;
format date mmddyy10.;
cards;
'01', 05/11/1960, 1
'01', 06/30/1960, 2
'04', 07/31/1995, 1
'22', 11/26/1969, 1
'22', 07/06/1981, 2
'22', 07/14/1986, 3
'22', 03/25/1992, 4
'22', 09/02/1993, 5
'22', 09/15/1993, 6
;

data want;
 set have;
 by id;
 retain temp ;
 if first.id then do;want=1;temp=date;end;
 if date-temp&amp;gt;180 then do;want+1;temp=date;end;
drop temp;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Mar 2024 04:33:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-enumerate-dated-events-within-x-days-of-each-other/m-p/919027#M361992</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-03-06T04:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to enumerate dated events within x days of each other?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-enumerate-dated-events-within-x-days-of-each-other/m-p/919098#M362025</link>
      <description>&lt;P&gt;Brilliant, Ksharp!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I don't understand why the "want+1" works correctly if the "want" variable is not retained. I think (incorrectly?) that "want" will only have a value of 1 for first.ID and otherwise will be set to missing. So how does "want" equal 2 when the formula (in my mind) is "missing (.) + 1"? It seems like the value of "want" is being retained from the prior record but this variable has not been listed in the "retain" statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help me understand?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2024 13:09:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-enumerate-dated-events-within-x-days-of-each-other/m-p/919098#M362025</guid>
      <dc:creator>samp945</dc:creator>
      <dc:date>2024-03-06T13:09:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to enumerate dated events within x days of each other?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-enumerate-dated-events-within-x-days-of-each-other/m-p/919114#M362032</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/415445"&gt;@samp945&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Brilliant, Ksharp!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I don't understand why the "want+1" works correctly if the "want" variable is not retained. I think (incorrectly?) that "want" will only have a value of 1 for first.ID and otherwise will be set to missing. So how does "want" equal 2 when the formula (in my mind) is "missing (.) + 1"? It seems like the value of "want" is being retained from the prior record but this variable has not been listed in the "retain" statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone help me understand?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your question is very observant.&amp;nbsp; The statement&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WANT+1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is a SAS "sum statement".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is effectively a replacement for&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;RETAIN WANT 0:
WANT=SUM(WANT,1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;See&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/id/pgmsascdc/9.4_3.5/lestmtsref/n1dfiqj146yi2cn1maeju9wo7ijs.htm" target="_self"&gt;Sum Statement&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will see frequent use of sum statements in many responses in this community.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2024 14:28:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-enumerate-dated-events-within-x-days-of-each-other/m-p/919114#M362032</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-03-06T14:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to enumerate dated events within x days of each other?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-enumerate-dated-events-within-x-days-of-each-other/m-p/919217#M362071</link>
      <description>Yes. variable WANT is retained due to SUM Statement "want+1".&lt;BR /&gt;As mkeintz pointed out ,  "want+1" already included statement "retain want 0" .</description>
      <pubDate>Thu, 07 Mar 2024 01:13:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-enumerate-dated-events-within-x-days-of-each-other/m-p/919217#M362071</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-03-07T01:13:17Z</dc:date>
    </item>
  </channel>
</rss>

