<?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 Would the Retain function help? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Would-the-Retain-function-help/m-p/313093#M270775</link>
    <description>&lt;P&gt;I have data that looks like this:&lt;/P&gt;&lt;P&gt;Obs &amp;nbsp; &amp;nbsp;Date &amp;nbsp; &amp;nbsp;CompanyID&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7/15/15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12/31/01 &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12/31/02 &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3/31/05 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5/15/05 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I need to do is keep the observations 1-4 and drop (or at least flag) observation 5. Observation 2 &amp;amp; 3 are not duplicates because there is a year in between those dates. Observations 4 and 5 will be treated as duplicates because they fall less than 60 days apart.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is the retain function appropriate?&lt;/P&gt;</description>
    <pubDate>Mon, 21 Nov 2016 15:04:54 GMT</pubDate>
    <dc:creator>cadams47</dc:creator>
    <dc:date>2016-11-21T15:04:54Z</dc:date>
    <item>
      <title>Would the Retain function help?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Would-the-Retain-function-help/m-p/313093#M270775</link>
      <description>&lt;P&gt;I have data that looks like this:&lt;/P&gt;&lt;P&gt;Obs &amp;nbsp; &amp;nbsp;Date &amp;nbsp; &amp;nbsp;CompanyID&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7/15/15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12/31/01 &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12/31/02 &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3/31/05 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5/15/05 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I need to do is keep the observations 1-4 and drop (or at least flag) observation 5. Observation 2 &amp;amp; 3 are not duplicates because there is a year in between those dates. Observations 4 and 5 will be treated as duplicates because they fall less than 60 days apart.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is the retain function appropriate?&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 15:04:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Would-the-Retain-function-help/m-p/313093#M270775</guid>
      <dc:creator>cadams47</dc:creator>
      <dc:date>2016-11-21T15:04:54Z</dc:date>
    </item>
    <item>
      <title>Re: Would the Retain function help?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Would-the-Retain-function-help/m-p/313098#M270776</link>
      <description>&lt;P&gt;Use the lag() function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by date;
run;
/* just to be sure */

data want;
set have;
if date - lag(date) le 60 then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Nov 2016 15:09:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Would-the-Retain-function-help/m-p/313098#M270776</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-21T15:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: Would the Retain function help?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Would-the-Retain-function-help/m-p/313101#M270777</link>
      <description>&lt;P&gt;But does that take into account each company? A company might have one observation or it might have three. How can I make those decisions by company?&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 15:11:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Would-the-Retain-function-help/m-p/313101#M270777</guid>
      <dc:creator>cadams47</dc:creator>
      <dc:date>2016-11-21T15:11:48Z</dc:date>
    </item>
    <item>
      <title>Re: Would the Retain function help?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Would-the-Retain-function-help/m-p/313106#M270778</link>
      <description>&lt;P&gt;Just modify the sort and use by-processing in the data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by company date;
run;

data want;
set have;
by company;
if date - lag(date) le 60 and not first.company then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Nov 2016 15:16:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Would-the-Retain-function-help/m-p/313106#M270778</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-21T15:16:37Z</dc:date>
    </item>
    <item>
      <title>Re: Would the Retain function help?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Would-the-Retain-function-help/m-p/313111#M270779</link>
      <description>&lt;P&gt;I'm still hesitant because a company could have four observations, with two being close in date and two being 60+ days:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CompanyID&lt;/P&gt;&lt;P&gt;5/15/05 &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;&lt;P&gt;6/30/05 &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;&lt;P&gt;6/30/09 &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;&lt;P&gt;6/30/10 &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this scenario, if I relied on first.company, it would delete three of them. Only the first one would need to go.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 15:21:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Would-the-Retain-function-help/m-p/313111#M270779</guid>
      <dc:creator>cadams47</dc:creator>
      <dc:date>2016-11-21T15:21:18Z</dc:date>
    </item>
    <item>
      <title>Re: Would the Retain function help?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Would-the-Retain-function-help/m-p/313122#M270780</link>
      <description>&lt;P&gt;It would keep three observations:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date :mmddyy8. companyid;
format date mmddyy8.;
cards;
5/15/05 4
6/30/05 4
6/30/09 4
6/30/10 4
;
run;

data want;
set have;
by companyid;
if date - lag(date) le 60 and not first.companyid then delete;
run;

proc print noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;    date    companyid

05/15/05        4    
06/30/09        4    
06/30/10        4    
&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Nov 2016 15:36:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Would-the-Retain-function-help/m-p/313122#M270780</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-21T15:36:49Z</dc:date>
    </item>
    <item>
      <title>Re: Would the Retain function help?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Would-the-Retain-function-help/m-p/313124#M270781</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This program outputs all records in which the date&amp;nbsp;&amp;gt; cutdate.&amp;nbsp; And cutdate is set to 60 days after the last "valid" date.&amp;nbsp; Except for the first case of company, when cutdate is set to missing (which is lower that all valid numeric values):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=cutdate);
  retain cutdate;
   set have;
   by companyid;
   if first.companyid then cutdate=.;
   if date&amp;gt;cutdate;
   cutdate=date+60;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;regards,&lt;/P&gt;
&lt;P&gt;Mark&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 15:46:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Would-the-Retain-function-help/m-p/313124#M270781</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-11-21T15:46:23Z</dc:date>
    </item>
    <item>
      <title>Re: Would the Retain function help?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Would-the-Retain-function-help/m-p/313174#M270782</link>
      <description>&lt;P&gt;Thank you everyone!&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 17:53:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Would-the-Retain-function-help/m-p/313174#M270782</guid>
      <dc:creator>cadams47</dc:creator>
      <dc:date>2016-11-21T17:53:01Z</dc:date>
    </item>
    <item>
      <title>Re: Would the Retain function help?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Would-the-Retain-function-help/m-p/313370#M270783</link>
      <description>&lt;P&gt;Please mark the answer that worked for you as solution, for future reference.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 07:38:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Would-the-Retain-function-help/m-p/313370#M270783</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-22T07:38:27Z</dc:date>
    </item>
    <item>
      <title>Re: Would the Retain function help?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Would-the-Retain-function-help/m-p/313438#M270784</link>
      <description>&lt;P&gt;I will once I figure out which one is better. Both left me with another issue.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 12:04:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Would-the-Retain-function-help/m-p/313438#M270784</guid>
      <dc:creator>cadams47</dc:creator>
      <dc:date>2016-11-22T12:04:29Z</dc:date>
    </item>
  </channel>
</rss>

