<?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 delete rows by set of two in a group in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-delete-rows-by-set-of-two-in-a-group/m-p/725665#M38327</link>
    <description>&lt;P&gt;Hum! you are close to a solution. One thing we must be advise of, usually, when we have a code 2 then we should have the code 1.&amp;nbsp; When we have a code 4 we should have a code 3.&amp;nbsp; When we have the code 6 we should have the code 5.&amp;nbsp; Otherwise, we could have a code 1, or 5 alone.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was trying the following approach... a select over partition with case statement but it does not seems to work. Do you already have use this approach.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table test2 as&lt;BR /&gt;(&lt;BR /&gt;select policy, code,&lt;BR /&gt;row_number() over ( partition by policy &lt;BR /&gt;order by case when (code = '1' and code= '2') then 0&lt;BR /&gt;when (code = '3' and code= '4') then 1&lt;BR /&gt;when (code = '5' and code= '6') then 2 &lt;BR /&gt;else 3 end ) As rownumber&lt;BR /&gt;from test&lt;BR /&gt;);&lt;/P&gt;
&lt;P&gt;quit;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So there after, you delete everything with rownumber between 0 and two.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could it works&lt;/P&gt;</description>
    <pubDate>Thu, 11 Mar 2021 22:32:09 GMT</pubDate>
    <dc:creator>alepage</dc:creator>
    <dc:date>2021-03-11T22:32:09Z</dc:date>
    <item>
      <title>How to delete rows by set of two in a group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-delete-rows-by-set-of-two-in-a-group/m-p/725601#M38324</link>
      <description>&lt;P&gt;DATA TEST;&lt;BR /&gt;LENGTH POLICY $10.;&lt;BR /&gt;INFILE DATALINES DLM='|';&lt;BR /&gt;INPUT POLICY $ CODE ;&lt;BR /&gt;DATALINES;&lt;BR /&gt;AAA|1&lt;BR /&gt;AAA|2&lt;BR /&gt;AAA|3&lt;BR /&gt;AAA|4&lt;BR /&gt;AAA|5&lt;BR /&gt;AAB|5&lt;BR /&gt;AAB|6&lt;BR /&gt;AAC|5&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;/* If we look at the code, the even code (2,4,6) are related to a cancellation.&lt;BR /&gt;so we have a code 1 and code 2 for the same policy, those lines should be deleted.&lt;BR /&gt;Same thing for code 3 and code 4, those lines should be deleted.&lt;BR /&gt;Again, same thing for code 5 and 6, those lines should be deleted. So at the end, the test table&lt;BR /&gt;should contains only the following lines: how do we do that either with sas code or proc sql, quit;&lt;BR /&gt;how do we do that?*/&lt;/P&gt;
&lt;P&gt;/* AAA|5&lt;BR /&gt;AAC|5&lt;BR /&gt;*/&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 20:19:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-delete-rows-by-set-of-two-in-a-group/m-p/725601#M38324</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2021-03-11T20:19:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete rows by set of two in a group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-delete-rows-by-set-of-two-in-a-group/m-p/725640#M38325</link>
      <description>&lt;P&gt;This sounds like you want to count the number of observations for each policy number, and if there are an even number of observations, then delete that group. If there are an odd number of observations, then keep the last observation. Does that sound correct? If so, you can use BY-group processing with the MOD function to get the results you want:&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data test2 (drop=cnt);&lt;BR /&gt;set test;&lt;BR /&gt;by policy;&lt;BR /&gt;if first.policy then cnt=0;&lt;BR /&gt;cnt+1;&lt;BR /&gt;if last.policy then do;&lt;BR /&gt;if MOD(cnt,2)=0 then delete;&lt;BR /&gt;else output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 21:46:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-delete-rows-by-set-of-two-in-a-group/m-p/725640#M38325</guid>
      <dc:creator>jebjur</dc:creator>
      <dc:date>2021-03-11T21:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete rows by set of two in a group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-delete-rows-by-set-of-two-in-a-group/m-p/725641#M38326</link>
      <description>Sounds like you're trying to make sense of transaction data.&lt;BR /&gt; &lt;BR /&gt;I would create two new variables. &lt;BR /&gt;VarOne would map (2, 4, 6) to (1, 3, 5) and the VarTwo would map (2, 4, 6) to (-1, -3, -5), respectively.&lt;BR /&gt;&lt;BR /&gt;Then sum varTwo, grouping by Policy and VarOne. &lt;BR /&gt;&lt;BR /&gt;Keep only records where the total sum is not 0. &lt;BR /&gt;&lt;BR /&gt;The mapping code tables can be automated if it's 1,2 as shown but if it's more complicated than that, you'll have to create it manually.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 11 Mar 2021 21:47:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-delete-rows-by-set-of-two-in-a-group/m-p/725641#M38326</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-11T21:47:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete rows by set of two in a group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-delete-rows-by-set-of-two-in-a-group/m-p/725665#M38327</link>
      <description>&lt;P&gt;Hum! you are close to a solution. One thing we must be advise of, usually, when we have a code 2 then we should have the code 1.&amp;nbsp; When we have a code 4 we should have a code 3.&amp;nbsp; When we have the code 6 we should have the code 5.&amp;nbsp; Otherwise, we could have a code 1, or 5 alone.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was trying the following approach... a select over partition with case statement but it does not seems to work. Do you already have use this approach.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table test2 as&lt;BR /&gt;(&lt;BR /&gt;select policy, code,&lt;BR /&gt;row_number() over ( partition by policy &lt;BR /&gt;order by case when (code = '1' and code= '2') then 0&lt;BR /&gt;when (code = '3' and code= '4') then 1&lt;BR /&gt;when (code = '5' and code= '6') then 2 &lt;BR /&gt;else 3 end ) As rownumber&lt;BR /&gt;from test&lt;BR /&gt;);&lt;/P&gt;
&lt;P&gt;quit;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So there after, you delete everything with rownumber between 0 and two.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could it works&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 22:32:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-delete-rows-by-set-of-two-in-a-group/m-p/725665#M38327</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2021-03-11T22:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete rows by set of two in a group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-delete-rows-by-set-of-two-in-a-group/m-p/725667#M38328</link>
      <description>No idea, I'm not familiar with PARTITION well enough to read that code without running it. It's not supported in SAS. &lt;BR /&gt;</description>
      <pubDate>Thu, 11 Mar 2021 22:37:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-delete-rows-by-set-of-two-in-a-group/m-p/725667#M38328</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-11T22:37:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete rows by set of two in a group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-delete-rows-by-set-of-two-in-a-group/m-p/725675#M38329</link>
      <description>I have test your solution with real data and my dataset is empty&lt;BR /&gt;</description>
      <pubDate>Thu, 11 Mar 2021 23:04:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-delete-rows-by-set-of-two-in-a-group/m-p/725675#M38329</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2021-03-11T23:04:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete rows by set of two in a group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-delete-rows-by-set-of-two-in-a-group/m-p/725700#M38330</link>
      <description>&lt;P&gt;I understand your task as follows.&amp;nbsp; Any time there is a code with an even value, there will have already been a code with a value exactly one less for the same policy.&amp;nbsp; The corresponding records should not be kept.&amp;nbsp; Keep only records with an odd code value, for which there is no code value exactly 1 greater for the same policy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the codes really are integers and the data are sorted by policy/code, then:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=nxt_:);
  set test (keep=policy);
  by policy;
  merge test
        test (firstobs=2 keep=code rename=(code=nxt_code));
  if mod(code,2)=1 and (nxt_code^=code+1 or last.policy=1);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Using the firstobs=2 you can look ahead one record and compare the code-in-hand against the next code.&amp;nbsp; If the code in hand is odd and either the next code is one greater, or the current record is the last for the current policy, then it is unmatched and should be output.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Mar 2021 03:24:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-delete-rows-by-set-of-two-in-a-group/m-p/725700#M38330</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-03-12T03:24:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete rows by set of two in a group</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-delete-rows-by-set-of-two-in-a-group/m-p/725900#M38333</link>
      <description>&lt;P&gt;Did you run my code against the test data set you specified in your post? Did it give you the results you wanted? If so, what is different in the test data set vs the real data? Were there any errors in the log when when you ran the code against your real data?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Mar 2021 19:50:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-delete-rows-by-set-of-two-in-a-group/m-p/725900#M38333</guid>
      <dc:creator>jebjur</dc:creator>
      <dc:date>2021-03-12T19:50:30Z</dc:date>
    </item>
  </channel>
</rss>

