<?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: Identify the model that was used to identify the max in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Identify-the-model-that-was-used-to-identify-the-max/m-p/620280#M182233</link>
    <description>&lt;P&gt;Not hard in SQL if you know what to group and boolean expressions&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id         model  $     grade       amount;
cards;
1             a               1               10
1             b               2               10
2             a               3               20
2             b               3               10
;

proc sql;
create table want(drop=t) as
select *, max(t) as max_model
from 
(select *,ifc(max(amount)=amount,model,' ') as t
from
(select *, max(grade) as max_grade from have group by id)
group by id,max_grade)
group by id,max_grade;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 27 Jan 2020 18:33:32 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-01-27T18:33:32Z</dc:date>
    <item>
      <title>Identify the model that was used to identify the max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-the-model-that-was-used-to-identify-the-max/m-p/620258#M182223</link>
      <description>&lt;P&gt;Hi SAS Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set where I am trying to find the max grade for each ID. This is simple enough using Proc SQL and then using a group by statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are two problems that I am running into , the first is I am trying to identify the model where the max grade comes from and assign that model for each row with the same ID. In the example below,&amp;nbsp; for ID #1 model&amp;nbsp;&lt;STRONG&gt;b&lt;/STRONG&gt; has a higher grade of 2 than&amp;nbsp;&lt;STRONG&gt;a&lt;/STRONG&gt; that only has a grade of 1, so model b would be assigned as the max_ model for ID #1..&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The second problem that I am trying to tackle is the same as the first problem with an added nuance, If there are multiple models that have the same highest grade for the ID, I want to pick the one one with the highest amount value. In the example below, for ID #2 has two models have the same max grade of 3. Since model a has a higher value, I would assign&amp;nbsp;&lt;STRONG&gt;a&lt;/STRONG&gt; to every row for ID 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is an example of my data&lt;/P&gt;&lt;P&gt;id&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;model&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;grade&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;amount&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I envision my data to look like in the end&lt;/P&gt;&lt;P&gt;id&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;model&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;grade&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;amount&amp;nbsp; &amp;nbsp; max_grade max_model&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please reach out if you have any questions or need me to clarify anything.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Tom&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2020 18:04:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-the-model-that-was-used-to-identify-the-max/m-p/620258#M182223</guid>
      <dc:creator>Tommy1</dc:creator>
      <dc:date>2020-01-27T18:04:00Z</dc:date>
    </item>
    <item>
      <title>Re: Identify the model that was used to identify the max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-the-model-that-was-used-to-identify-the-max/m-p/620262#M182224</link>
      <description>&lt;P&gt;PROC SUMMARY allows you to identify the ID value (where ID can be any variable) that produces the maximum. Here is an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=proc&amp;amp;docsetVersion=9.4&amp;amp;docsetTarget=n18axszmd7up03n1densx922oe8y.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;https://documentation.sas.com/?docsetId=proc&amp;amp;docsetVersion=9.4&amp;amp;docsetTarget=n18axszmd7up03n1densx922oe8y.htm&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As far as the second problem, I think you'd have to do some coding in a DATA step or SQL.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2020 18:10:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-the-model-that-was-used-to-identify-the-max/m-p/620262#M182224</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-27T18:10:09Z</dc:date>
    </item>
    <item>
      <title>Re: Identify the model that was used to identify the max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-the-model-that-was-used-to-identify-the-max/m-p/620264#M182225</link>
      <description>&lt;P&gt;Use BY group + SORT&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this, untested.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by ID descending grade descending amount;
run;

data max;
set have;

by ID ;

if first.ID;
rename grade=max_grade model = max_model;
drop amount;
run;

data want;
merge have max;
by ID;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/104359"&gt;@Tommy1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi SAS Community,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a data set where I am trying to find the max grade for each ID. This is simple enough using Proc SQL and then using a group by statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are two problems that I am running into , the first is I am trying to identify the model where the max grade comes from and assign that model for each row with the same ID. In the example below,&amp;nbsp; for ID #1 model&amp;nbsp;&lt;STRONG&gt;b&lt;/STRONG&gt; has a higher grade of 2 than&amp;nbsp;&lt;STRONG&gt;a&lt;/STRONG&gt; that only has a grade of 1, so model b would be assigned as the max_ model for ID #1..&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second problem that I am trying to tackle is the same as the first problem with an added nuance, If there are multiple models that have the same highest grade for the ID, I want to pick the one one with the highest amount value. In the example below, for ID #2 has two models have the same max grade of 3. Since model a has a higher value, I would assign&amp;nbsp;&lt;STRONG&gt;a&lt;/STRONG&gt; to every row for ID 2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is an example of my data&lt;/P&gt;
&lt;P&gt;id&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;model&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;grade&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;amount&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is what I envision my data to look like in the end&lt;/P&gt;
&lt;P&gt;id&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;model&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;grade&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;amount&amp;nbsp; &amp;nbsp; max_grade max_model&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please reach out if you have any questions or need me to clarify anything.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2020 18:12:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-the-model-that-was-used-to-identify-the-max/m-p/620264#M182225</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-27T18:12:32Z</dc:date>
    </item>
    <item>
      <title>Re: Identify the model that was used to identify the max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-the-model-that-was-used-to-identify-the-max/m-p/620274#M182228</link>
      <description>&lt;P&gt;For huge data sets, wouldn't a SORT be more time consuming than PROC SUMMARY?&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2020 18:32:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-the-model-that-was-used-to-identify-the-max/m-p/620274#M182228</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-27T18:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: Identify the model that was used to identify the max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-the-model-that-was-used-to-identify-the-max/m-p/620278#M182231</link>
      <description>Yes, but this handles both conditions at once which is more efficient from a programming standpoint &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Mon, 27 Jan 2020 18:32:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-the-model-that-was-used-to-identify-the-max/m-p/620278#M182231</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-27T18:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: Identify the model that was used to identify the max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-the-model-that-was-used-to-identify-the-max/m-p/620279#M182232</link>
      <description>&lt;P&gt;I think this tackles it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
id=1;             model='a';      grade=1;       amount=10; output;
id=1;             model='b';      grade=2;       amount=10; output;
id=2;             model='a';      grade=3;       amount=20; output;
id=2;             model='b';      grade=3;       amount=10; output;
run;

proc sort data=have out=have_sort;
by id descending grade descending amount model;
run;

data want (drop=max_amount);
set have_sort;
by id;
retain max_grade max_amount max_model;
if first.id then do; max_grade = grade; max_model = model; max_amount=amount; end;
if grade &amp;gt; max_grade then do; max_grade = grade; max_model = model; end;
else if grade=max_grade and amount &amp;gt; max_amount then do; max_grade = grade; max_model = model; end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could also do this in proc sql qith nested queries, but that second criteria would be a bit tricky.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2020 18:32:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-the-model-that-was-used-to-identify-the-max/m-p/620279#M182232</guid>
      <dc:creator>JeffMaggio</dc:creator>
      <dc:date>2020-01-27T18:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: Identify the model that was used to identify the max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-the-model-that-was-used-to-identify-the-max/m-p/620280#M182233</link>
      <description>&lt;P&gt;Not hard in SQL if you know what to group and boolean expressions&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id         model  $     grade       amount;
cards;
1             a               1               10
1             b               2               10
2             a               3               20
2             b               3               10
;

proc sql;
create table want(drop=t) as
select *, max(t) as max_model
from 
(select *,ifc(max(amount)=amount,model,' ') as t
from
(select *, max(grade) as max_grade from have group by id)
group by id,max_grade)
group by id,max_grade;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Jan 2020 18:33:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-the-model-that-was-used-to-identify-the-max/m-p/620280#M182233</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-27T18:33:32Z</dc:date>
    </item>
    <item>
      <title>Re: Identify the model that was used to identify the max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-the-model-that-was-used-to-identify-the-max/m-p/620295#M182239</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;
input id         model  $     grade       amount;
cards;
1             a               1               10
1             b               2               10
2             a               3               20
2             b               3               10
;

data want;
 if _n_=1 then do;
  dcl hash H () ;
  h.definekey  ("max_grade") ;
  h.definedata ("_amt", "_m") ;
  h.definedone () ;
 end;
 do _n_=1 by 1 until(last.id);
  set have;
  by id;
  length max_model _m $32;
  if grade&amp;lt;max_grade then continue;
  max_grade=grade;
  max_model=model;
  if h.find()=0 and _amt&amp;gt;amount then max_model=_m;
  else do; _amt=amount;_m=model;end;
  h.replace();
 end;
 do _n_=1 to _n_;
  set have;
  output;
 end;
 drop _:;
 h.clear();
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Jan 2020 19:30:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-the-model-that-was-used-to-identify-the-max/m-p/620295#M182239</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-27T19:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: Identify the model that was used to identify the max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-the-model-that-was-used-to-identify-the-max/m-p/620296#M182240</link>
      <description>&lt;P&gt;You will need a data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have; by id descending grade descending amount; run;

data want;
set have;
by id;
retain max_grade max_model;
if first.id then do;
	max_grade = grade;
	max_model = model;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;solves both problems.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2020 19:22:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-the-model-that-was-used-to-identify-the-max/m-p/620296#M182240</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-01-27T19:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: Identify the model that was used to identify the max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-the-model-that-was-used-to-identify-the-max/m-p/620344#M182269</link>
      <description>&lt;P&gt;Wow! Thank you all so much for all the solutions! The knowledge and speed that you responded to my post blew me away. This shows just how wonderful a place the SAS community is. I wish I could accept multiple solutions because there were so many different ways that you all helped me approach the problem. I am not sure if there is a certain e&lt;SPAN&gt;tiquette&amp;nbsp;&lt;/SPAN&gt;for which solution to pick, but I went with the one that was the most simple and easiest for me to implement with my data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank You!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2020 21:20:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-the-model-that-was-used-to-identify-the-max/m-p/620344#M182269</guid>
      <dc:creator>Tommy1</dc:creator>
      <dc:date>2020-01-27T21:20:41Z</dc:date>
    </item>
  </channel>
</rss>

