<?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: Distinct Value for one column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Distinct-Value-for-one-column/m-p/535080#M146889</link>
    <description>&lt;P&gt;Since you have no duplicates, this should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT; 
  set HAVE;
&amp;nbsp; by ID;
&amp;nbsp; if&amp;nbsp;DIRECTION = 'North' and first.ID and last.ID;
&amp;nbsp;run;&lt;/CODE&gt;&lt;/PRE&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, 13 Feb 2019 03:38:19 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2019-02-13T03:38:19Z</dc:date>
    <item>
      <title>Distinct Value for one column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinct-Value-for-one-column/m-p/535076#M146886</link>
      <description>&lt;P&gt;&lt;BR /&gt;From the given dataset, I am trying to filter certain values from the Variable.&lt;BR /&gt;Example: There are 2 columns, (ID and Direction) , I need to create a new dataset with Variable Direction having value only North. Eg, My code should pick ID 2, 4 only. I don't need the combination. Only ID's having North Direction.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID Direction&lt;BR /&gt;1 South&lt;BR /&gt;1 North&lt;BR /&gt;1 West&lt;BR /&gt;1 East&lt;BR /&gt;2 North&lt;BR /&gt;3 South&lt;BR /&gt;3 North&lt;BR /&gt;3 West&lt;BR /&gt;4 North&lt;BR /&gt;5 South&lt;BR /&gt;6 West&lt;BR /&gt;6 East&lt;/P&gt;&lt;P&gt;7 South&lt;/P&gt;&lt;P&gt;7 North&lt;BR /&gt;data one multi;&lt;BR /&gt;length _c $10;&lt;BR /&gt;call missing(__c,_f);&lt;BR /&gt;do until(last.ID);&lt;BR /&gt;set test;&lt;BR /&gt;by id direction notsorted;&lt;BR /&gt;if _c ne direction then __c+1;&lt;BR /&gt;_c=direction;&lt;BR /&gt;if direction="NORTH" then _f=1;&lt;BR /&gt;end;&lt;BR /&gt;do until(last.id);&lt;BR /&gt;set TEST;&lt;BR /&gt;by id direction notsorted;&lt;BR /&gt;if __c=1 then output one;&lt;BR /&gt;else output multi&lt;/P&gt;&lt;P&gt;end;&lt;BR /&gt;drop _:;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 03:06:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinct-Value-for-one-column/m-p/535076#M146886</guid>
      <dc:creator>Kalai2008</dc:creator>
      <dc:date>2019-02-13T03:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Value for one column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinct-Value-for-one-column/m-p/535079#M146888</link>
      <description>&lt;P&gt;straight forward sql:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Direction $ ;
cards;
1 South
1 North
1 West
1 East
2 North
3 South
3 North
3 West
4 North
5 South
6 West
6 East
7 South
7 North
;

proc sql;
create table want as
select *
from have 
group by id
having direction='North' and count(distinct direction)=1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Feb 2019 03:35:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinct-Value-for-one-column/m-p/535079#M146888</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-13T03:35:53Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Value for one column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinct-Value-for-one-column/m-p/535080#M146889</link>
      <description>&lt;P&gt;Since you have no duplicates, this should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT; 
  set HAVE;
&amp;nbsp; by ID;
&amp;nbsp; if&amp;nbsp;DIRECTION = 'North' and first.ID and last.ID;
&amp;nbsp;run;&lt;/CODE&gt;&lt;/PRE&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, 13 Feb 2019 03:38:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinct-Value-for-one-column/m-p/535080#M146889</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-02-13T03:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Value for one column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinct-Value-for-one-column/m-p/535082#M146890</link>
      <description>&lt;P&gt;English is a tricky language.&lt;/P&gt;
&lt;P&gt;I think that you are asking to find the IDs that only have Direction='North'.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your rows are distinct (that is you cannot have the same ID and Direction repeated) then this means you want IDS that have only one observation AND that observation has Direction='North'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set test;
  by id;
  if first.id and last.id and direction='North';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Perhaps you want something like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data north(keep=id) south(keep=id) east(keep=id) west=(keep=id) multi;
  set test;
  by id ;
  if not (first.id and last.id) then output multi;
  else if direction='North' then output north;
  else if direction='South' then output south;
  else if direction='East' then output east;
  else if direction='West' then output west;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Feb 2019 03:39:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinct-Value-for-one-column/m-p/535082#M146890</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-02-13T03:39:24Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Value for one column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinct-Value-for-one-column/m-p/535084#M146892</link>
      <description>Why isn't ID=3 selected, it has a North value?&lt;BR /&gt;</description>
      <pubDate>Wed, 13 Feb 2019 03:52:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinct-Value-for-one-column/m-p/535084#M146892</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-13T03:52:45Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Value for one column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinct-Value-for-one-column/m-p/535086#M146894</link>
      <description>&lt;P&gt;Id has to have &lt;STRONG&gt;&lt;U&gt;only&lt;/U&gt; &lt;/STRONG&gt;north &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You must be tired mam&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 03:54:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinct-Value-for-one-column/m-p/535086#M146894</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-13T03:54:11Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Value for one column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinct-Value-for-one-column/m-p/535087#M146895</link>
      <description>&lt;P&gt;Perfect...You saved my time.. Thank you ..It worked, simple SQL code.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 03:59:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinct-Value-for-one-column/m-p/535087#M146895</guid>
      <dc:creator>Kalai2008</dc:creator>
      <dc:date>2019-02-13T03:59:35Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Value for one column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinct-Value-for-one-column/m-p/535088#M146896</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Id has to have &lt;STRONG&gt;&lt;U&gt;only&lt;/U&gt; &lt;/STRONG&gt;north &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You must be tired mam&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;lol, I actually am. Did a full day of work and then presentations to students and finally eating dinner now!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 04:00:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinct-Value-for-one-column/m-p/535088#M146896</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-13T04:00:11Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Value for one column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinct-Value-for-one-column/m-p/535089#M146897</link>
      <description>&lt;P&gt;lol That makes two . Just did a microwave instant noodles (lazy &amp;amp; tired). Gonna sleep in a bit. Good night and sleep tight. Take care!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 04:07:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinct-Value-for-one-column/m-p/535089#M146897</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-13T04:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Value for one column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinct-Value-for-one-column/m-p/535091#M146899</link>
      <description>&lt;P&gt;Thank you and your code worked . My dataset is very huge with 100 variables, over half a million records. I just gave an example, but in real,the column Direction&amp;nbsp; have many Values. Rows are not distinct, ID's and Direction repeats itself , having duplicates due to other variables.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 04:25:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinct-Value-for-one-column/m-p/535091#M146899</guid>
      <dc:creator>Kalai2008</dc:creator>
      <dc:date>2019-02-13T04:25:14Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Value for one column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinct-Value-for-one-column/m-p/535092#M146900</link>
      <description>&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 04:26:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinct-Value-for-one-column/m-p/535092#M146900</guid>
      <dc:creator>Kalai2008</dc:creator>
      <dc:date>2019-02-13T04:26:03Z</dc:date>
    </item>
  </channel>
</rss>

