<?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: Date within two weeks in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Date-within-two-weeks/m-p/457283#M29462</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id date :date9.;
  format date date9.;
  datalines;
1 07JAN2018
2 28MAR2018
3 14FEB2018
1 28JAN2018
2 11APR2018
3 24FEB2018
;
run;

data temp;
 set have;
 if id=1 then group+1;
run;
proc sort data=temp;
by id descending group;
run;
data temp;
 set temp;
 dif=dif(date);
 if id=lag(id) and abs(dif)&amp;lt;=14 then flag='yes';
   else flag='no';
run;
proc sort data=temp out=want;
by group id;
run;
proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 25 Apr 2018 13:51:46 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-04-25T13:51:46Z</dc:date>
    <item>
      <title>Date within two weeks</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Date-within-two-weeks/m-p/456964#M29439</link>
      <description>&lt;P&gt;I have a id and date column and I want to find out if the id had a second within 2 weeks(14 days);&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; date&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 07JAN2018&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 28MAR2018&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 14FEB2018&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 28JAN2018&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 11APR2018&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 24FEB2018&lt;/P&gt;&lt;P&gt;..&lt;/P&gt;&lt;P&gt;..&lt;/P&gt;&lt;P&gt;..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OUTPUT:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;STRONG&gt;&amp;nbsp;SEEN within 2 weeks(14 days from the first date)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 07JAN2018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; No&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 28MAR2018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; yes&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 14FEB2018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; yes&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 28JAN2018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 11APR2018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 24FEB2018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Apr 2018 21:22:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Date-within-two-weeks/m-p/456964#M29439</guid>
      <dc:creator>hk2013</dc:creator>
      <dc:date>2018-04-24T21:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: Date within two weeks</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Date-within-two-weeks/m-p/456975#M29440</link>
      <description>&lt;P&gt;Please show what you expect for output for your example input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Week" is a somewhat slippery concept. By within two weeks do you mean 14 days, do you have any rules about "workdays" "weekdays", which day of a week starts a week.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And the ever popular is your date variable actually a SAS date valued variable?&lt;/P&gt;</description>
      <pubDate>Tue, 24 Apr 2018 17:25:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Date-within-two-weeks/m-p/456975#M29440</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-04-24T17:25:29Z</dc:date>
    </item>
    <item>
      <title>Re: Date within two weeks</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Date-within-two-weeks/m-p/457113#M29446</link>
      <description>output example is included i just want a col that if there is a next date within 14 days it says yes or no</description>
      <pubDate>Tue, 24 Apr 2018 23:01:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Date-within-two-weeks/m-p/457113#M29446</guid>
      <dc:creator>hk2013</dc:creator>
      <dc:date>2018-04-24T23:01:37Z</dc:date>
    </item>
    <item>
      <title>Re: Date within two weeks</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Date-within-two-weeks/m-p/457139#M29448</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/169082"&gt;@hk2013&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Below should work. Please post next time your sample data via a working SAS data step as I've done below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id date :date9.;
  format date date9.;
  datalines;
1 07JAN2018
2 28MAR2018
3 14FEB2018
1 28JAN2018
2 11APR2018
3 24FEB2018
;
run;

proc sql;
  create table want as
  select 
    o.*, 
    case
      when
            (select i.date from have i 
              where i.id=o.id 
                    and i.date between o.date+1 and o.date+14
            ) ne . then 'Yes'
      else 'No'
      end as YesNo length=3
  from have o 
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Apr 2018 02:19:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Date-within-two-weeks/m-p/457139#M29448</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-04-25T02:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: Date within two weeks</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Date-within-two-weeks/m-p/457283#M29462</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id date :date9.;
  format date date9.;
  datalines;
1 07JAN2018
2 28MAR2018
3 14FEB2018
1 28JAN2018
2 11APR2018
3 24FEB2018
;
run;

data temp;
 set have;
 if id=1 then group+1;
run;
proc sort data=temp;
by id descending group;
run;
data temp;
 set temp;
 dif=dif(date);
 if id=lag(id) and abs(dif)&amp;lt;=14 then flag='yes';
   else flag='no';
run;
proc sort data=temp out=want;
by group id;
run;
proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Apr 2018 13:51:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Date-within-two-weeks/m-p/457283#M29462</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-04-25T13:51:46Z</dc:date>
    </item>
  </channel>
</rss>

