<?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: Eliminating observations with datasets in long form in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Eliminating-observations-with-datasets-in-long-form/m-p/244717#M45632</link>
    <description>&lt;P&gt;Create a new variable that captures the 7 day interval start and compare the dates to the variable to determine which records are kept and which are dropped. Based on your example, the following should work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
informat date mmddyy10.;
format date date9.;
input ID           ClaimID                Date ;
cards; 
1                     1                  1/1/2015         
1                     2                  1/7/2015         
1                     3                  1/9/2015         
1                     4                  1/10/2015       
1                     5                  1/16/2015 
;
run; 

data want;
set have;
by id;
retain cutoff7;

if first.id then cutoff7=date;
else if date-cutoff7&amp;lt;=7 then delete;
else cutoff7=date;
run;
	&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 20 Jan 2016 15:28:15 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-01-20T15:28:15Z</dc:date>
    <item>
      <title>Eliminating observations with datasets in long form</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eliminating-observations-with-datasets-in-long-form/m-p/244716#M45631</link>
      <description>&lt;P&gt;I am working with a medical claims dataset with variables ID (enrollee ID), claimID (a unique identifier for each claim), and the date of service. For this example, assume that claimID 1-5 are all claims for&amp;nbsp;the same medical service, and I only want to count services *within an individual* that occurred during&amp;nbsp;a 7 day period as one service (this is because there are sometimes duplicate claims with dates of service that are in close proximity). &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For this example, claimID 1 would be kept and claimID 2 would be deleted because it's within 6 days of claimID 1. &amp;nbsp;However, claimID 3 would be kept even though it's within 2 days of claimID 2 because claimID 2 will be deleted and claimID 3 is more than 7 days away from claimID 1. &amp;nbsp;ClaimID 4 and ClaimID 5 would be deleted because they are within 7 days of ClaimID 3, which will be kept. &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; &amp;nbsp; ClaimID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &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;&lt;/P&gt;
&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1/1/2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1/7/2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1/9/2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1/10/2015 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1/16/2015 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the solution might be to create a loop that finds a claim that needs to be eliminated because it's within 7 days of the first claim; as soon as such a claim is detected, the loop exits and the claim is eliminated from the dataset.&amp;nbsp; On the next iteration of the loop, SAS starts over from the first claim and finds if there is another claim that needs to be eliminated because it's within 7 days; if not, SAS will keep the next the next claim that needs to be deduplicated, etc. &amp;nbsp;But I'm not sure exactly how to&amp;nbsp;implement this. &amp;nbsp;I'd appreciate any advice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 15:18:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eliminating-observations-with-datasets-in-long-form/m-p/244716#M45631</guid>
      <dc:creator>chuakp</dc:creator>
      <dc:date>2016-01-20T15:18:07Z</dc:date>
    </item>
    <item>
      <title>Re: Eliminating observations with datasets in long form</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eliminating-observations-with-datasets-in-long-form/m-p/244717#M45632</link>
      <description>&lt;P&gt;Create a new variable that captures the 7 day interval start and compare the dates to the variable to determine which records are kept and which are dropped. Based on your example, the following should work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
informat date mmddyy10.;
format date date9.;
input ID           ClaimID                Date ;
cards; 
1                     1                  1/1/2015         
1                     2                  1/7/2015         
1                     3                  1/9/2015         
1                     4                  1/10/2015       
1                     5                  1/16/2015 
;
run; 

data want;
set have;
by id;
retain cutoff7;

if first.id then cutoff7=date;
else if date-cutoff7&amp;lt;=7 then delete;
else cutoff7=date;
run;
	&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jan 2016 15:28:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eliminating-observations-with-datasets-in-long-form/m-p/244717#M45632</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-01-20T15:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Eliminating observations with datasets in long form</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eliminating-observations-with-datasets-in-long-form/m-p/244719#M45634</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
format date MMDDYY10.;
input ID ClaimID Date MMDDYY10.;
cards;
1 1 1/1/2015         
1 2 1/7/2015         
1 3 1/9/2015         
1 4 1/10/2015       
1 5 1/16/2015 
;
run;

data want;
set have;
by ID;
retain fdate ;
if first.ID then fdate=date; 
else if intck('day',fdate,date) &amp;lt;= 7 then delete;
else fdate=date;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jan 2016 15:43:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eliminating-observations-with-datasets-in-long-form/m-p/244719#M45634</guid>
      <dc:creator>mohamed_zaki</dc:creator>
      <dc:date>2016-01-20T15:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: Eliminating observations with datasets in long form</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eliminating-observations-with-datasets-in-long-form/m-p/244750#M45647</link>
      <description>&lt;P&gt;Thanks, Reeza - this worked. &amp;nbsp;Also, thanks to mohamed_zaki - your solution appears to have worked as well.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 16:34:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eliminating-observations-with-datasets-in-long-form/m-p/244750#M45647</guid>
      <dc:creator>chuakp</dc:creator>
      <dc:date>2016-01-20T16:34:55Z</dc:date>
    </item>
  </channel>
</rss>

