<?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: proc sort not deduping by all in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/proc-sort-not-deduping-by-all/m-p/861653#M82548</link>
    <description>&lt;P&gt;Based on my testing SAS is actually smart enough to determine that the source data has already been sorted with option nodupkey.&lt;/P&gt;
&lt;P&gt;Have a look at below test case.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  do i=3,8,4,3,3;
    var='x';
    output;
  end;
run;

proc sort data=test;
  by _all_;
run;

proc sort data=test nodupkey;
  by _all_;
run;

proc sort data=test nodupkey;
  by _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;28         data test;
29           do i=3,8,4,3,3;
30             var='x';
31             output;
32           end;
33         run;

NOTE: The data set WORK.TEST has 5 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

34         
35         proc sort data=test;
36           by _all_;
37         run;

NOTE: There were 5 observations read from the data set WORK.TEST.
NOTE: The data set WORK.TEST has 5 observations and 2 variables.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

38         
39         proc sort data=test nodupkey;
40           by _all_;
41         run;

NOTE: There were 5 observations read from the data set WORK.TEST.
NOTE: 2 observations with duplicate key values were deleted.
NOTE: The data set WORK.TEST has 3 observations and 2 variables.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

42         
43         proc sort data=test nodupkey;
44           by _all_;
45         run;

NOTE: Input data set is already sorted, no sorting done.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds&lt;/PRE&gt;
&lt;P&gt;Proc Sort is already around since so long that I would have been very astonished if there still would have been such a fundamental bug in it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you run a Proc Contents against the table sorted with nodupkey then you'll see that SAS stores in the table metadata that the table is sorted, by which variables in which order and with which options.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1677648243727.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80973i832C7B4BD75FB5FE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1677648243727.png" alt="Patrick_0-1677648243727.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 01 Mar 2023 05:24:10 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2023-03-01T05:24:10Z</dc:date>
    <item>
      <title>proc sort not deduping by all</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sort-not-deduping-by-all/m-p/861606#M82539</link>
      <description>&lt;P&gt;proc sort nodupkey data=data;by _ALL_; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;does not work. the log just says the data is already sorted. it does not dedupe even though I'm seeing duplicate rows. why does this not work?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2023 22:02:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sort-not-deduping-by-all/m-p/861606#M82539</guid>
      <dc:creator>toomanystepsint</dc:creator>
      <dc:date>2023-02-28T22:02:08Z</dc:date>
    </item>
    <item>
      <title>Re: proc sort not deduping by all</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sort-not-deduping-by-all/m-p/861632#M82544</link>
      <description>&lt;P&gt;Actual compare two of the observations that LOOK the same to see what differences there are.&lt;/P&gt;
&lt;P&gt;So assuming the two observations that look like a duplicates are number 5 and number 6 you could run this code to compare them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one two;
  set data firstobs=5 obs=6;
  if _n_=1 then output one;
  else output two;
run;
proc compare data=one compare=two;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Mar 2023 00:33:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sort-not-deduping-by-all/m-p/861632#M82544</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-01T00:33:41Z</dc:date>
    </item>
    <item>
      <title>Re: proc sort not deduping by all</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sort-not-deduping-by-all/m-p/861653#M82548</link>
      <description>&lt;P&gt;Based on my testing SAS is actually smart enough to determine that the source data has already been sorted with option nodupkey.&lt;/P&gt;
&lt;P&gt;Have a look at below test case.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  do i=3,8,4,3,3;
    var='x';
    output;
  end;
run;

proc sort data=test;
  by _all_;
run;

proc sort data=test nodupkey;
  by _all_;
run;

proc sort data=test nodupkey;
  by _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;28         data test;
29           do i=3,8,4,3,3;
30             var='x';
31             output;
32           end;
33         run;

NOTE: The data set WORK.TEST has 5 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

34         
35         proc sort data=test;
36           by _all_;
37         run;

NOTE: There were 5 observations read from the data set WORK.TEST.
NOTE: The data set WORK.TEST has 5 observations and 2 variables.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

38         
39         proc sort data=test nodupkey;
40           by _all_;
41         run;

NOTE: There were 5 observations read from the data set WORK.TEST.
NOTE: 2 observations with duplicate key values were deleted.
NOTE: The data set WORK.TEST has 3 observations and 2 variables.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

42         
43         proc sort data=test nodupkey;
44           by _all_;
45         run;

NOTE: Input data set is already sorted, no sorting done.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds&lt;/PRE&gt;
&lt;P&gt;Proc Sort is already around since so long that I would have been very astonished if there still would have been such a fundamental bug in it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you run a Proc Contents against the table sorted with nodupkey then you'll see that SAS stores in the table metadata that the table is sorted, by which variables in which order and with which options.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1677648243727.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80973i832C7B4BD75FB5FE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1677648243727.png" alt="Patrick_0-1677648243727.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 05:24:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sort-not-deduping-by-all/m-p/861653#M82548</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-03-01T05:24:10Z</dc:date>
    </item>
    <item>
      <title>Re: proc sort not deduping by all</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sort-not-deduping-by-all/m-p/861668#M82550</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/438688"&gt;@toomanystepsint&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;proc sort nodupkey data=data;by _ALL_; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;does not work. the log just says the data is already sorted. it does not dedupe even though I'm seeing duplicate rows. why does this not work?&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Just adding to my previous post: I bet that you don't have real duplicate rows after running proc sort as posted above.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One reason that can lead to rows that look like duplicates are non printable characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to "force" a resort then you could just create a new table and sort this one.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort nodupkey data=data;by _ALL_; run;

data take2;
  set data;
run;

proc sort nodupkey data=take2;by _ALL_; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;By creating a new dataset the metadata sort information will get lost and though Proc Sort will resort the new table.&lt;BR /&gt;You will get the exactly same result but sometimes seeing is believing.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 07:39:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sort-not-deduping-by-all/m-p/861668#M82550</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-03-01T07:39:08Z</dc:date>
    </item>
    <item>
      <title>Re: proc sort not deduping by all</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sort-not-deduping-by-all/m-p/861756#M82554</link>
      <description>&lt;P&gt;The formats assigned to variables can have different values, used by Proc Sort, that appear identical to users.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A simple example:&lt;/P&gt;
&lt;PRE&gt;data example;
   input x;
   format x 5.1;
datalines;
1.1
1.11
1.111
1.1111
;

proc sort data=example out=sorted nodupkey;
   by x;
run;&lt;/PRE&gt;
&lt;P&gt;The default format assigned to x only displays 1 decimal (rounding as needed). ALL the values with that format appear the same but none are. So the sort does not remove any of them.&lt;/P&gt;
&lt;P&gt;Other types of formats can have different appearance but similar result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 15:40:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sort-not-deduping-by-all/m-p/861756#M82554</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-01T15:40:17Z</dc:date>
    </item>
  </channel>
</rss>

