<?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: Removing duplicates depending on preceeding observation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-depending-on-preceeding-observation/m-p/497122#M131652</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/39747"&gt;@Cornelis&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you, this is a good alternative.&lt;/P&gt;
&lt;P&gt;A demonstration that there are more solution. Very good learning point!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;AND that you should double check your data step code before posting. The example you provided generates all missing values for PHASE because you missed the period as part of the informat.&lt;/P&gt;
&lt;P&gt;If you had supplied the better informat:&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; obs @&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt; phase $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;4.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;The values for phase would be&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;1 A&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;2 A&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;3 B &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;because it would have been reading the phase from column 1 and the informat as specified forces reading up to 4 characters. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Note that &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;@'s solution does not have the @1 in the input statement.&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 19 Sep 2018 20:26:42 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-09-19T20:26:42Z</dc:date>
    <item>
      <title>Removing duplicates depending on preceeding observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-depending-on-preceeding-observation/m-p/496853#M131519</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please deliver me the solution to remove duplicates based on this set:&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; a;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; obs @&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt; phase $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;cards&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 A&lt;/P&gt;
&lt;P&gt;2 A&lt;/P&gt;
&lt;P&gt;3 B&lt;/P&gt;
&lt;P&gt;4 B&lt;/P&gt;
&lt;P&gt;5 B&lt;/P&gt;
&lt;P&gt;6 A&lt;/P&gt;
&lt;P&gt;7 B&lt;/P&gt;
&lt;P&gt;8 A&lt;/P&gt;
&lt;P&gt;9 B&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The outcome must be:&lt;/P&gt;
&lt;P&gt;1 A&lt;/P&gt;
&lt;P&gt;3 B&lt;/P&gt;
&lt;P&gt;6 A&lt;/P&gt;
&lt;P&gt;7 B&lt;/P&gt;
&lt;P&gt;8 A&lt;/P&gt;
&lt;P&gt;9 B&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a multiple set of subgroups, but the outcome must be always in the order A,B,A,B,A,B, ...or B,A,B,A,B, ... where the first A and B&amp;nbsp;must be selected from the subgroup.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope that you have a fast solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cornelis&lt;/P&gt;</description>
      <pubDate>Wed, 19 Sep 2018 08:39:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-depending-on-preceeding-observation/m-p/496853#M131519</guid>
      <dc:creator>Cornelis</dc:creator>
      <dc:date>2018-09-19T08:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates depending on preceeding observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-depending-on-preceeding-observation/m-p/496856#M131520</link>
      <description>&lt;P&gt;Use proc sort with option nodupkey.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have nodupkey;&lt;/P&gt;
&lt;P&gt;by obs;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Sep 2018 08:43:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-depending-on-preceeding-observation/m-p/496856#M131520</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-09-19T08:43:18Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates depending on preceeding observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-depending-on-preceeding-observation/m-p/496858#M131522</link>
      <description>&lt;P&gt;Thank you for your swift reply.&lt;/P&gt;
&lt;P&gt;Actually not the solution, the row numbers (obs) are all unique.&lt;/P&gt;
&lt;P&gt;Applying nodupkey will not results into solution since the list will be remained intact.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Sep 2018 08:47:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-depending-on-preceeding-observation/m-p/496858#M131522</guid>
      <dc:creator>Cornelis</dc:creator>
      <dc:date>2018-09-19T08:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates depending on preceeding observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-depending-on-preceeding-observation/m-p/496865#M131526</link>
      <description>&lt;P&gt;Oops ! Right. Sorry, answered too fast.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On your sorted dataset;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data want;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;lp=lag(phase);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lp ne phase;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; drop lp;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Sep 2018 09:07:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-depending-on-preceeding-observation/m-p/496865#M131526</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-09-19T09:07:19Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates depending on preceeding observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-depending-on-preceeding-observation/m-p/496940#M131552</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input obs  phase $;
cards;
1 A
2 A
3 B
4 B
5 B
6 A
7 B
8 A
9 B
;
run;

data want;
 set a;
 by phase notsorted;
 if first.phase;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Sep 2018 12:54:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-depending-on-preceeding-observation/m-p/496940#M131552</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-09-19T12:54:31Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates depending on preceeding observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-depending-on-preceeding-observation/m-p/496942#M131554</link>
      <description>&lt;P&gt;Great, tank you for your support!&lt;/P&gt;
&lt;P&gt;Indeed, lag function is better.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Sep 2018 12:55:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-depending-on-preceeding-observation/m-p/496942#M131554</guid>
      <dc:creator>Cornelis</dc:creator>
      <dc:date>2018-09-19T12:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates depending on preceeding observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-depending-on-preceeding-observation/m-p/496945#M131555</link>
      <description>&lt;P&gt;Thank you, this is a good alternative.&lt;/P&gt;
&lt;P&gt;A demonstration that there are more solution. Very good learning point!&lt;/P&gt;</description>
      <pubDate>Wed, 19 Sep 2018 12:58:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-depending-on-preceeding-observation/m-p/496945#M131555</guid>
      <dc:creator>Cornelis</dc:creator>
      <dc:date>2018-09-19T12:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates depending on preceeding observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-depending-on-preceeding-observation/m-p/497122#M131652</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/39747"&gt;@Cornelis&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you, this is a good alternative.&lt;/P&gt;
&lt;P&gt;A demonstration that there are more solution. Very good learning point!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;AND that you should double check your data step code before posting. The example you provided generates all missing values for PHASE because you missed the period as part of the informat.&lt;/P&gt;
&lt;P&gt;If you had supplied the better informat:&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; obs @&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt; phase $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;4.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;The values for phase would be&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;1 A&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;2 A&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;3 B &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;because it would have been reading the phase from column 1 and the informat as specified forces reading up to 4 characters. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Note that &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;@'s solution does not have the @1 in the input statement.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Sep 2018 20:26:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-depending-on-preceeding-observation/m-p/497122#M131652</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-09-19T20:26:42Z</dc:date>
    </item>
  </channel>
</rss>

