<?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: Custom Dedupe and Sorting By Two Columns in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Custom-Dedupe-and-Sorting-By-Two-Columns/m-p/693558#M37350</link>
    <description>&lt;P&gt;Do it in a single step with hash objects:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input a b;
datalines;
1 7
1 8
1 9
2 7
2 8
2 9
3 7
3 8
3 9
;

data want;
set have;
if _n_ = 1 then do;
    dcl hash ha();
    ha.definekey("a");
    ha.definedone();
    dcl hash hb();
    hb.definekey("b");
    hb.definedone();
    end;
if ha.check() and hb.check() then do;
    output;
    rc = ha.add();
    rc = hb.add();
    end;
drop rc;
run;

proc print data=want; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 82px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50909iBD731C01094E5526/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 22 Oct 2020 16:23:52 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2020-10-22T16:23:52Z</dc:date>
    <item>
      <title>Custom Dedupe and Sorting By Two Columns</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Custom-Dedupe-and-Sorting-By-Two-Columns/m-p/693547#M37349</link>
      <description>&lt;P&gt;Hi, so I have a table that looks like this:&lt;BR /&gt;&lt;BR /&gt;Field 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Field 2&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to be able to sort this table in a way that makes it look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a working for solution for when this happens 2 or 3 times, but I was wondering if there was a clever shorter solution than:&lt;/P&gt;&lt;P&gt;1. Creating a table A that sorts by fields 1 and 2&lt;/P&gt;&lt;P&gt;2. Deduping table A by field 1&lt;/P&gt;&lt;P&gt;3. Deduping table A by field 2&lt;/P&gt;&lt;P&gt;4. Creating a table B that sorts by fields 1 and 2, that does not have the field 1 and field 2 found in table A.&lt;/P&gt;&lt;P&gt;5. Repeat this as many times as necessary to get a table A that has "1, 7", table B with "2, 8" and table C with "3, 9"&lt;/P&gt;&lt;P&gt;6. Union the final tables together.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2020 15:39:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Custom-Dedupe-and-Sorting-By-Two-Columns/m-p/693547#M37349</guid>
      <dc:creator>lawatkey</dc:creator>
      <dc:date>2020-10-22T15:39:10Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Dedupe and Sorting By Two Columns</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Custom-Dedupe-and-Sorting-By-Two-Columns/m-p/693558#M37350</link>
      <description>&lt;P&gt;Do it in a single step with hash objects:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input a b;
datalines;
1 7
1 8
1 9
2 7
2 8
2 9
3 7
3 8
3 9
;

data want;
set have;
if _n_ = 1 then do;
    dcl hash ha();
    ha.definekey("a");
    ha.definedone();
    dcl hash hb();
    hb.definekey("b");
    hb.definedone();
    end;
if ha.check() and hb.check() then do;
    output;
    rc = ha.add();
    rc = hb.add();
    end;
drop rc;
run;

proc print data=want; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 82px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50909iBD731C01094E5526/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2020 16:23:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Custom-Dedupe-and-Sorting-By-Two-Columns/m-p/693558#M37350</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-10-22T16:23:52Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Dedupe and Sorting By Two Columns</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Custom-Dedupe-and-Sorting-By-Two-Columns/m-p/693559#M37351</link>
      <description>&lt;P&gt;If your actual data has any other variables at all you should provide some examples and what is done with them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some details:&lt;/P&gt;
&lt;P&gt;Are the values always the same 1,7&amp;nbsp;&amp;nbsp;&amp;nbsp; 2,8&amp;nbsp;&amp;nbsp; 3,9&lt;/P&gt;
&lt;P&gt;or are the field values always the same between the Field1 but could be different?&lt;/P&gt;
&lt;P&gt;Are the field1 values always sequential?&lt;/P&gt;
&lt;P&gt;Are the field2 always sequential?&amp;nbsp; (some programming approaches that might work for sequential won't work when not)&lt;/P&gt;
&lt;P&gt;Are ALL the field2 values present for ALL field1 values?&lt;/P&gt;
&lt;P&gt;Are there the same number of values for field1 and field2?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your example this does what is asked.&lt;/P&gt;
&lt;PRE&gt;data have;
input Field1  Field2;
datalines;
1	7
1	8
1	9
2	7
2	8
2	9
3	7
3	8
3	9
;

proc sort data=have(keep=field1) out=temp1
     nodupkey;
     by field1;
run;

proc sort data=have(keep=field2) out=temp2
     nodupkey;
     by field2;
run;

data want;
   merge temp1 temp2;
run;&lt;/PRE&gt;
&lt;P&gt;If the number of values of field1 and field2 do not match this likely doesn't work. You need to provide example of what should happen in this case.&lt;/P&gt;
&lt;P&gt;Note: any other variables are excluded.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2020 16:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Custom-Dedupe-and-Sorting-By-Two-Columns/m-p/693559#M37351</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-22T16:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Dedupe and Sorting By Two Columns</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Custom-Dedupe-and-Sorting-By-Two-Columns/m-p/693700#M37356</link>
      <description>&lt;PRE&gt;data have;
input a b;
datalines;
1 7
1 8
1 9
2 7
2 8
2 9
3 7
3 8
3 9
;
data want;
n+1;
 do i=1 by 1 until(last.a);
  set have;
  by a;
  if i=n then output;
 end;
drop i n;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Oct 2020 11:19:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Custom-Dedupe-and-Sorting-By-Two-Columns/m-p/693700#M37356</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-10-23T11:19:14Z</dc:date>
    </item>
  </channel>
</rss>

