<?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: Filter data on a variable &amp;amp; unique observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Filter-data-on-a-variable-amp-unique-observations/m-p/372463#M276048</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;'s&amp;nbsp;suggestion is the most compact.&amp;nbsp; But if this is really about how to use proc sort for your purpose, then you should (1) sort ALL the records number, not just the 'A' records,&amp;nbsp;and (2) read back the sorted file, with the 'A' record preceding non-'A' records for each number, and (3) keep the desired records:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[editted on Wed 7/5 - there is no IF function.&amp;nbsp; I should have used IFN function, corrected below]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have out=need;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; by number;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; set have (where=(region='A'))&amp;nbsp;&amp;nbsp; have (where=(region^='A'));&lt;/P&gt;
&lt;P&gt;&amp;nbsp; by number;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if first.number then keeprec=ifn(region='A',1,0);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; retain keeprec;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if keeprec;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 06 Jul 2017 01:53:04 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2017-07-06T01:53:04Z</dc:date>
    <item>
      <title>Filter data on a variable &amp; unique observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-data-on-a-variable-amp-unique-observations/m-p/372420#M276046</link>
      <description>&lt;P&gt;Hi, In the attached sample data set I have added the input &amp;amp; output data required. I tried to use nodupkey for unique records but did not get the desired output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data = sasuser.sample nodupkey out=sasuser.sample2;&lt;BR /&gt;by number;&lt;BR /&gt;where region contains 'A';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Only first 3 rows of required output were displayed instead of all 6 rows.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in Advance.&amp;nbsp;&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>Sat, 01 Jul 2017 14:36:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-data-on-a-variable-amp-unique-observations/m-p/372420#M276046</guid>
      <dc:creator>dhir</dc:creator>
      <dc:date>2017-07-01T14:36:52Z</dc:date>
    </item>
    <item>
      <title>Re: Filter data on a variable &amp; unique observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-data-on-a-variable-amp-unique-observations/m-p/372435#M276047</link>
      <description>&lt;P&gt;Do it with sql:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table want as select * 
   from sasuser.sample where number in
       (select distinct number &lt;BR /&gt;         from &lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;sasuser.sample &lt;BR /&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;         where region = "A") ; quit; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Jul 2017 18:14:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-data-on-a-variable-amp-unique-observations/m-p/372435#M276047</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-07-01T18:14:34Z</dc:date>
    </item>
    <item>
      <title>Re: Filter data on a variable &amp; unique observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-data-on-a-variable-amp-unique-observations/m-p/372463#M276048</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;'s&amp;nbsp;suggestion is the most compact.&amp;nbsp; But if this is really about how to use proc sort for your purpose, then you should (1) sort ALL the records number, not just the 'A' records,&amp;nbsp;and (2) read back the sorted file, with the 'A' record preceding non-'A' records for each number, and (3) keep the desired records:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[editted on Wed 7/5 - there is no IF function.&amp;nbsp; I should have used IFN function, corrected below]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have out=need;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; by number;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; set have (where=(region='A'))&amp;nbsp;&amp;nbsp; have (where=(region^='A'));&lt;/P&gt;
&lt;P&gt;&amp;nbsp; by number;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if first.number then keeprec=ifn(region='A',1,0);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; retain keeprec;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if keeprec;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2017 01:53:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-data-on-a-variable-amp-unique-observations/m-p/372463#M276048</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-07-06T01:53:04Z</dc:date>
    </item>
    <item>
      <title>Re: Filter data on a variable &amp; unique observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-data-on-a-variable-amp-unique-observations/m-p/372522#M276049</link>
      <description>&lt;P&gt;Thank you, Shmuel. works perfectly.&lt;/P&gt;</description>
      <pubDate>Sun, 02 Jul 2017 11:38:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-data-on-a-variable-amp-unique-observations/m-p/372522#M276049</guid>
      <dc:creator>dhir</dc:creator>
      <dc:date>2017-07-02T11:38:18Z</dc:date>
    </item>
    <item>
      <title>Re: Filter data on a variable &amp; unique observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-data-on-a-variable-amp-unique-observations/m-p/372523#M276050</link>
      <description>&lt;P&gt;Hi mkeintz,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First part of code worked, need created but second part returned the attached error.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have changed the file names in your code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=sasuser.sample out=sasuser.need;&lt;BR /&gt;by number;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set sasuser.need (where=(region='A')) sasuser.need (where=(region^='A'));&lt;BR /&gt;by number;&lt;BR /&gt;if first.number then keeprec=if(region='A',1,0);&lt;BR /&gt;retain keeprec;&lt;BR /&gt;if keeprec;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Help me correct any mistakes here.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&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;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/14019i3D33439DA4C33049/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="1.png" title="1.png" /&gt;</description>
      <pubDate>Sun, 02 Jul 2017 11:49:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-data-on-a-variable-amp-unique-observations/m-p/372523#M276050</guid>
      <dc:creator>dhir</dc:creator>
      <dc:date>2017-07-02T11:49:33Z</dc:date>
    </item>
  </channel>
</rss>

