<?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 Creating a new variable for a group based on maximum value of another variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-for-a-group-based-on-maximum-value-of/m-p/478895#M286430</link>
    <description>&lt;P&gt;I have a dataset&amp;nbsp; that looks like the following&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Customer Type Value&lt;/P&gt;&lt;P&gt;A&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; 10&lt;/P&gt;&lt;P&gt;A&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; 10&lt;/P&gt;&lt;P&gt;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;20&lt;BR /&gt;B&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;15&lt;/P&gt;&lt;P&gt;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;30&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The eventual goal is to not have multiple types of customer. I want to have a condition where the max(value) is used to determine the type of a customer. For customer A, the max(value) is 20. So based on that, I want to take Type=2 and change it for all 3 instances for customer A (potentially create a new variable Type_1). I have created the max value for each customer group but cannot figure out how to set the logic for changing the type.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Customer Type Value Type_1&lt;/P&gt;&lt;P&gt;A&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; 10&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;A&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; 10&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;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;20&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;BR /&gt;B&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;15&amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;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;30&amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Jul 2018 05:06:35 GMT</pubDate>
    <dc:creator>eemrun</dc:creator>
    <dc:date>2018-07-18T05:06:35Z</dc:date>
    <item>
      <title>Creating a new variable for a group based on maximum value of another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-for-a-group-based-on-maximum-value-of/m-p/478895#M286430</link>
      <description>&lt;P&gt;I have a dataset&amp;nbsp; that looks like the following&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Customer Type Value&lt;/P&gt;&lt;P&gt;A&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; 10&lt;/P&gt;&lt;P&gt;A&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; 10&lt;/P&gt;&lt;P&gt;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;20&lt;BR /&gt;B&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;15&lt;/P&gt;&lt;P&gt;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;30&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The eventual goal is to not have multiple types of customer. I want to have a condition where the max(value) is used to determine the type of a customer. For customer A, the max(value) is 20. So based on that, I want to take Type=2 and change it for all 3 instances for customer A (potentially create a new variable Type_1). I have created the max value for each customer group but cannot figure out how to set the logic for changing the type.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Customer Type Value Type_1&lt;/P&gt;&lt;P&gt;A&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; 10&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;A&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; 10&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;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;20&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;BR /&gt;B&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;15&amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;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;30&amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 05:06:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-for-a-group-based-on-maximum-value-of/m-p/478895#M286430</guid>
      <dc:creator>eemrun</dc:creator>
      <dc:date>2018-07-18T05:06:35Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable for a group based on maximum value of another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-for-a-group-based-on-maximum-value-of/m-p/478900#M286431</link>
      <description>&lt;P&gt;your output sample plz?&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 04:06:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-for-a-group-based-on-maximum-value-of/m-p/478900#M286431</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-18T04:06:10Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable for a group based on maximum value of another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-for-a-group-based-on-maximum-value-of/m-p/478903#M286432</link>
      <description>Apologies. Updated original post.</description>
      <pubDate>Wed, 18 Jul 2018 04:21:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-for-a-group-based-on-maximum-value-of/m-p/478903#M286432</guid>
      <dc:creator>eemrun</dc:creator>
      <dc:date>2018-07-18T04:21:05Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable for a group based on maximum value of another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-for-a-group-based-on-maximum-value-of/m-p/478906#M286433</link>
      <description>&lt;P&gt;shouldn't type_1 value for customerb be 1 instead of 2? I'm not getting the logic&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 04:24:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-for-a-group-based-on-maximum-value-of/m-p/478906#M286433</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-18T04:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable for a group based on maximum value of another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-for-a-group-based-on-maximum-value-of/m-p/478907#M286434</link>
      <description>the type_1 value should be based on the highest of 'value' field. since highest 'value' for customer B is 30, then type_1 should be 2 for customer B</description>
      <pubDate>Wed, 18 Jul 2018 04:43:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-for-a-group-based-on-maximum-value-of/m-p/478907#M286434</guid>
      <dc:creator>eemrun</dc:creator>
      <dc:date>2018-07-18T04:43:09Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable for a group based on maximum value of another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-for-a-group-based-on-maximum-value-of/m-p/478911#M286435</link>
      <description>&lt;P&gt;Ok then why is it 2 for customerA&amp;nbsp; when highest value 20 has 1 for type variable?&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 05:04:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-for-a-group-based-on-maximum-value-of/m-p/478911#M286435</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-18T05:04:28Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable for a group based on maximum value of another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-for-a-group-based-on-maximum-value-of/m-p/478913#M286436</link>
      <description>Fudge it! That was a bad mistake. Took me this long to see that! it should be 1. Apologies my friend.</description>
      <pubDate>Wed, 18 Jul 2018 05:07:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-for-a-group-based-on-maximum-value-of/m-p/478913#M286436</guid>
      <dc:creator>eemrun</dc:creator>
      <dc:date>2018-07-18T05:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable for a group based on maximum value of another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-for-a-group-based-on-maximum-value-of/m-p/478915#M286437</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Customer $ Type Value ;
cards;
A               2        10
A               2        10
A               1         20
B               1         15
B               2         30
;

proc sql;
create table want(drop=m) as
select *,max(m) as type_1
from (select *,(max(value)=value)*type as m from have group by customer)
group by customer;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Jul 2018 05:17:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-for-a-group-based-on-maximum-value-of/m-p/478915#M286437</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-18T05:17:35Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable for a group based on maximum value of another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-for-a-group-based-on-maximum-value-of/m-p/478919#M286438</link>
      <description>&lt;P&gt;easiest perhaps&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 customer descending value;
run;
data want;
set have;
by customer;
retain type_1;
if first.customer then type_1=type;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Jul 2018 05:24:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-for-a-group-based-on-maximum-value-of/m-p/478919#M286438</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-18T05:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable for a group based on maximum value of another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-for-a-group-based-on-maximum-value-of/m-p/479761#M286439</link>
      <description>perfect....thanks!</description>
      <pubDate>Thu, 19 Jul 2018 23:35:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-for-a-group-based-on-maximum-value-of/m-p/479761#M286439</guid>
      <dc:creator>eemrun</dc:creator>
      <dc:date>2018-07-19T23:35:03Z</dc:date>
    </item>
  </channel>
</rss>

