<?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: Selecting distinct Combinations in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-distinct-Combinations/m-p/250632#M6729</link>
    <description>&lt;P&gt;I think you need to sort with the by variables first.&lt;/P&gt;</description>
    <pubDate>Wed, 17 Feb 2016 14:48:51 GMT</pubDate>
    <dc:creator>fengyuwuzu</dc:creator>
    <dc:date>2016-02-17T14:48:51Z</dc:date>
    <item>
      <title>Selecting distinct Combinations</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-distinct-Combinations/m-p/158863#M2869</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;suppose I have the following file:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" height="130" style="border: 1px solid rgb(0, 0, 0); width: 352px; height: 132px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;Name&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;Date&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;someinfo&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2010&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;a&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2010&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;a&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2009&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;b&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2009&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;b&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I would like to get is:&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" height="125" style="border: 1px solid rgb(0, 0, 0); width: 350px; height: 127px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;Name&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;Date&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;someinfo&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2010&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;a&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2009&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;b&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That is, I would like to get all the columns from my table but with the name/date combination being distinct&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Dec 2014 04:17:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-distinct-Combinations/m-p/158863#M2869</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2014-12-21T04:17:53Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting distinct Combinations</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-distinct-Combinations/m-p/158864#M2870</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Proc sql; select distinct ....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Dec 2014 04:34:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-distinct-Combinations/m-p/158864#M2870</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2014-12-21T04:34:39Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting distinct Combinations</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-distinct-Combinations/m-p/158865#M2871</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Patrick and thanks for the reply.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did the select distinct but it only gave me the 2 selected columns, but what I would like to get if possible is all the columns (like in the small example that I put in the question), in other words to delete all the name/date combination duplicates&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also tried to do&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data board_summary6;&lt;/P&gt;&lt;P&gt;set board_summary6;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;by comp_name date;&lt;/P&gt;&lt;P&gt;if first.comp_name and first.date;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but got an error message ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Dec 2014 04:49:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-distinct-Combinations/m-p/158865#M2871</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2014-12-21T04:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting distinct Combinations</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-distinct-Combinations/m-p/158866#M2872</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I actually could distinct select all the columns of interest but the thing is that since there are many of them I thought if its possible to make a shortcut by selecting the entire row corresponding to the name/date combination...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Dec 2014 04:57:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-distinct-Combinations/m-p/158866#M2872</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2014-12-21T04:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting distinct Combinations</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-distinct-Combinations/m-p/158867#M2873</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hope that helps:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile datalines truncover;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input name $ date someinfo $;&lt;/P&gt;&lt;P&gt;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;A 2010 a&lt;/P&gt;&lt;P&gt;A 2010 a&lt;/P&gt;&lt;P&gt;A 2009 b&lt;/P&gt;&lt;P&gt;A 2009 b&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table want1 as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select distinct *&lt;/P&gt;&lt;P&gt;&amp;nbsp; from have;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=have out=want2 nodupkey;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by _all_;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=have out=inter3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by name date someinfo;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set inter3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by name date someinfo;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.someinfo;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And a fourth option:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if 0 then set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; dcl hash h1(dataset:'have');&lt;/P&gt;&lt;P&gt;&amp;nbsp; _rc=h1.defineKey(all:'y');&lt;/P&gt;&lt;P&gt;&amp;nbsp; _rc=h1.defineData(all:'y');&lt;/P&gt;&lt;P&gt;&amp;nbsp; _rc=h1.defineDone();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; _rc=h1.output(dataset:'Want4');&lt;/P&gt;&lt;P&gt;&amp;nbsp; stop;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Dec 2014 05:01:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-distinct-Combinations/m-p/158867#M2873</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2014-12-21T05:01:00Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting distinct Combinations</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-distinct-Combinations/m-p/158868#M2874</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure what you mean.&lt;/P&gt;&lt;P&gt;Sounds like you want to keep only one record for each distinct by group, but that you have extra non-key variables.&lt;/P&gt;&lt;P&gt;You can just use PROC SORT with the NODUPKEY option. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=have out=want NODUPKEY ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by name date;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Dec 2014 05:04:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-distinct-Combinations/m-p/158868#M2874</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-12-21T05:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting distinct Combinations</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-distinct-Combinations/m-p/158869#M2875</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And the fifth option:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;proc summary data=have nway;
 class _all_;
 output out=want(drop=_:);
run;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And the sixth optioin:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;proc freq data=have noprint;
 table name*date*someinfo/list out=want1(drop=count percent) nofreq norow nocol nopercent nocum;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Dec 2014 05:58:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-distinct-Combinations/m-p/158869#M2875</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-12-21T05:58:46Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting distinct Combinations</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-distinct-Combinations/m-p/158870#M2876</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks a lot to all, now I have a lot to choose from!!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Dec 2014 13:20:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-distinct-Combinations/m-p/158870#M2876</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2014-12-21T13:20:35Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting distinct Combinations</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-distinct-Combinations/m-p/250632#M6729</link>
      <description>&lt;P&gt;I think you need to sort with the by variables first.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2016 14:48:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-distinct-Combinations/m-p/250632#M6729</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2016-02-17T14:48:51Z</dc:date>
    </item>
  </channel>
</rss>

