<?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 Proc-SQL-MINID-equivalent in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-MINID-equivalent/m-p/311628#M67408</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking for an SQL-equivalent to this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data A;
  Infile Datalines DLM='09'x;
  Format ID $15.;
  Input ID $ Costs ;
  ID_short=Scan(ID,1,'_');
  Datalines;
460_01	45
460_02	50
460_03	60
461_01	99
461_02	98
461_03	100
463_01	45
463_02_469_01	40
463_03_469_01	40
463_04_469_01	40
463_05	55
;
Run;

Proc Means Data=A NoPrint;
  By ID_Short;
  Var Costs;
  Output Out=B (Drop=_:) MinID(Costs(ID))=ID Min=;
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;.. the problem ist of course, that there are multiple results for ID_short='463'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thx&lt;/P&gt;</description>
    <pubDate>Tue, 15 Nov 2016 09:20:24 GMT</pubDate>
    <dc:creator>user24feb</dc:creator>
    <dc:date>2016-11-15T09:20:24Z</dc:date>
    <item>
      <title>Proc-SQL-MINID-equivalent</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-MINID-equivalent/m-p/311628#M67408</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking for an SQL-equivalent to this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data A;
  Infile Datalines DLM='09'x;
  Format ID $15.;
  Input ID $ Costs ;
  ID_short=Scan(ID,1,'_');
  Datalines;
460_01	45
460_02	50
460_03	60
461_01	99
461_02	98
461_03	100
463_01	45
463_02_469_01	40
463_03_469_01	40
463_04_469_01	40
463_05	55
;
Run;

Proc Means Data=A NoPrint;
  By ID_Short;
  Var Costs;
  Output Out=B (Drop=_:) MinID(Costs(ID))=ID Min=;
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;.. the problem ist of course, that there are multiple results for ID_short='463'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thx&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2016 09:20:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-MINID-equivalent/m-p/311628#M67408</guid>
      <dc:creator>user24feb</dc:creator>
      <dc:date>2016-11-15T09:20:24Z</dc:date>
    </item>
    <item>
      <title>Re: Proc-SQL-MINID-equivalent</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-MINID-equivalent/m-p/311635#M67414</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select t1.ID_Short, t1.minimum as costs, min(t2.id) as id from
(
(
select ID_Short,min(Costs) as minimum
from a
group by ID_Short
) as t1
left join
(
select *
from a
) as t2
on t1.ID_Short=t2.ID_Short and t1.minimum=t2.Costs
)
group by t1.ID_Short, t1.minimum
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Nov 2016 10:08:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-MINID-equivalent/m-p/311635#M67414</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2016-11-15T10:08:52Z</dc:date>
    </item>
    <item>
      <title>Re: Proc-SQL-MINID-equivalent</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-MINID-equivalent/m-p/311640#M67417</link>
      <description>&lt;P&gt;May be you meant to do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;Proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;Means&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;Data&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;A NoPrint&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token statement"&gt;By&lt;/SPAN&gt; ID_Short&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token keyword"&gt;Var&lt;/SPAN&gt; Costs&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  Output Out&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;B &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;Drop&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;_:&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;STRONG&gt;IDGROUP&lt;/STRONG&gt;(min(costs) &lt;SPAN class="token keyword"&gt;out[3]&lt;/SPAN&gt; (costs)=&lt;SPAN class="token function"&gt;Min_costs&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;Run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2016 10:22:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-MINID-equivalent/m-p/311640#M67417</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-11-15T10:22:40Z</dc:date>
    </item>
    <item>
      <title>Re: Proc-SQL-MINID-equivalent</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-MINID-equivalent/m-p/311650#M67425</link>
      <description>&lt;PRE&gt;
Which one you would retain if there are multiple obs for '463'.

Data A;
  Infile Datalines expandtabs;
  Format ID $15.;
  Input ID $ Costs ;
  ID_short=Scan(ID,1,'_');
  Datalines;
460_01	45
460_02	50
460_03	60
461_01	99
461_02	98
461_03	100
463_01	45
463_02_469_01	40
463_03_469_01	40
463_04_469_01	40
463_05	55
;
Run;

proc sql;
create table want as
select * from (
 select *
  from a
   group by id_short
    having costs=min(costs)
)
group by id_short,costs
 having id=min(id);
quit;


&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Nov 2016 11:24:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-MINID-equivalent/m-p/311650#M67425</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-15T11:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: Proc-SQL-MINID-equivalent</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-MINID-equivalent/m-p/311660#M67428</link>
      <description>.. a random one, since the solution is not unique.</description>
      <pubDate>Tue, 15 Nov 2016 12:16:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-MINID-equivalent/m-p/311660#M67428</guid>
      <dc:creator>user24feb</dc:creator>
      <dc:date>2016-11-15T12:16:24Z</dc:date>
    </item>
  </channel>
</rss>

