<?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: Picking unique observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Picking-unique-observations/m-p/615041#M179863</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/240770"&gt;@Ranjeeta&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Datastep picks only unique occurrences of the values, i.e the value that occurs only once the dataset&lt;/P&gt;
&lt;P&gt;2. Proc SQL,- sorts, eliminates the dup occurrences from all , limits to one from all occurrences and outputs . So you would indeed have the difference. HTH&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, Select distinct can be considered an equivalent of proc sort nodupkey or if first.key in datastep&lt;/P&gt;</description>
    <pubDate>Fri, 03 Jan 2020 19:30:20 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-01-03T19:30:20Z</dc:date>
    <item>
      <title>Picking unique observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Picking-unique-observations/m-p/615039#M179861</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=deno_2 out=deno_2sorted;
by HCNE;
run;

data deno_3v1;
set deno_2sorted;
by HCNE;
if first.HCNE and last.HCNE;
run;&lt;BR /&gt;/*72,122*/

proc sql; create table deno_3 as
select distinct HCNE
from deno_2
;
quit;*78,368 , make sure unique patient only;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hello Can someone advise why the 2 codes above would return different results&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2020 19:18:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Picking-unique-observations/m-p/615039#M179861</guid>
      <dc:creator>Ranjeeta</dc:creator>
      <dc:date>2020-01-03T19:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: Picking unique observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Picking-unique-observations/m-p/615041#M179863</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/240770"&gt;@Ranjeeta&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Datastep picks only unique occurrences of the values, i.e the value that occurs only once the dataset&lt;/P&gt;
&lt;P&gt;2. Proc SQL,- sorts, eliminates the dup occurrences from all , limits to one from all occurrences and outputs . So you would indeed have the difference. HTH&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, Select distinct can be considered an equivalent of proc sort nodupkey or if first.key in datastep&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2020 19:30:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Picking-unique-observations/m-p/615041#M179863</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-03T19:30:20Z</dc:date>
    </item>
    <item>
      <title>Re: Picking unique observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Picking-unique-observations/m-p/615042#M179864</link>
      <description>&lt;P&gt;In the data step you're selecting only rows which are already unique in the source table (first AND last).&lt;/P&gt;
&lt;P&gt;The SQL is deduping the rows from the source table so it also returns a unique row where you've got duplicates in source.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data deno_2;
  hcne=1; output;
  hcne=2; output;output;
  stop;
run;

proc sort data=deno_2 out=deno_2sorted;
  by HCNE;
run;

/* only pick rows already unique in source */
data ds1_1;
  set deno_2sorted;
  by HCNE;
  if first.HCNE and last.HCNE;
run;

proc sql;
  create table ds1_2 as
    select HCNE
    from deno_2
    group by hcne
    having count(*)=1
  ;
quit;

/* dedup rows from source */
data ds2_1;
  set deno_2sorted;
  by HCNE;
  if first.HCNE;
run;

proc sql;
  create table ds2_2 as
    select distinct HCNE
    from deno_2
  ;
quit;

proc sort data=deno_2 out=ds2_3 nodupkey;
  by hcne;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2020 20:28:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Picking-unique-observations/m-p/615042#M179864</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-01-03T20:28:18Z</dc:date>
    </item>
  </channel>
</rss>

