<?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 How to select the maximum of a cluster inside a variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-the-maximum-of-a-cluster-inside-a-variable/m-p/727074#M226064</link>
    <description>&lt;P&gt;Hi all SAS Users,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset named ave_mar as below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;gviidkey	x1	    x2	    ave_mar_cap
001166_01W	0	    3	    781881399.22
001166_02W	0	    3	    782818024.77
001166_01   0       3       59988888.13
001491_01W	0	    3	    211021885.49
001855_03W	0	    3	    7490455.1517
001932_01W	0	    3	    6966150208.8
001945_01W	0	    3	    3661586156.1
002162_01W	0	    3	    2576720.9485
002162_02W	0	    3	    2163731.9025
002338_01W	0	    3	    772042538.92
002410_01W	0	    3	    79948092816
002411_01W	0	    3	    33749159713
002411_03W	0	    3	    84226468905&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;gviidkey&lt;/STRONG&gt; is made by &lt;STRONG&gt;gvkey&lt;/STRONG&gt; (must be &lt;STRONG&gt;6 first character&lt;/STRONG&gt;) and &lt;STRONG&gt;iid&lt;/STRONG&gt; (&lt;STRONG&gt;either 3 or 2 last character&lt;/STRONG&gt;). For example: gviidkey &lt;STRONG&gt;001166_01w&lt;/STRONG&gt;, in which &lt;STRONG&gt;001166&lt;/STRONG&gt; is gvkey and &lt;STRONG&gt;01w&lt;/STRONG&gt; is iid. In case gviidkey= &lt;STRONG&gt;001166_01&lt;/STRONG&gt;, in which &lt;STRONG&gt;034555&lt;/STRONG&gt; is gvkey and &lt;STRONG&gt;01&lt;/STRONG&gt; is iid.&lt;/P&gt;
&lt;P&gt;It can ben seen from the dataset above is there are some observations that the gviidkey are similar, what I want is select the &lt;STRONG&gt;gviidkey&lt;/STRONG&gt; that its &lt;STRONG&gt;ave_mar_cap&lt;/STRONG&gt; is highest&amp;nbsp; amongst all gviidkey of this gvkey.&lt;/P&gt;
&lt;P&gt;Simplistically speaking, what I want as below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;gviidkey	x1	    x2	    ave_mar_cap
001166_02W	0	    3	    782818024.77
001491_01W	0	    3	    211021885.49
001855_03W	0	    3	    7490455.1517
001932_01W	0	    3	    6966150208.8
002162_01W	0	    3	    2576720.9485
002338_01W	0	    3	    772042538.92
002410_01W	0	    3	    79948092816
002411_03W	0	    3	    84226468905&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If my explaining is not clear, please let me know.&lt;/P&gt;
&lt;P&gt;My novice idea is: create a variable named gvkey, then do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=ave_mar;
  by gvkey;
 var ave_mar_cap;
output out=want max=selected;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I am not sure it is correct or there is any other way to do so as well&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Warm regards.&lt;/P&gt;</description>
    <pubDate>Wed, 17 Mar 2021 12:34:02 GMT</pubDate>
    <dc:creator>Phil_NZ</dc:creator>
    <dc:date>2021-03-17T12:34:02Z</dc:date>
    <item>
      <title>How to select the maximum of a cluster inside a variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-the-maximum-of-a-cluster-inside-a-variable/m-p/727074#M226064</link>
      <description>&lt;P&gt;Hi all SAS Users,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset named ave_mar as below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;gviidkey	x1	    x2	    ave_mar_cap
001166_01W	0	    3	    781881399.22
001166_02W	0	    3	    782818024.77
001166_01   0       3       59988888.13
001491_01W	0	    3	    211021885.49
001855_03W	0	    3	    7490455.1517
001932_01W	0	    3	    6966150208.8
001945_01W	0	    3	    3661586156.1
002162_01W	0	    3	    2576720.9485
002162_02W	0	    3	    2163731.9025
002338_01W	0	    3	    772042538.92
002410_01W	0	    3	    79948092816
002411_01W	0	    3	    33749159713
002411_03W	0	    3	    84226468905&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;gviidkey&lt;/STRONG&gt; is made by &lt;STRONG&gt;gvkey&lt;/STRONG&gt; (must be &lt;STRONG&gt;6 first character&lt;/STRONG&gt;) and &lt;STRONG&gt;iid&lt;/STRONG&gt; (&lt;STRONG&gt;either 3 or 2 last character&lt;/STRONG&gt;). For example: gviidkey &lt;STRONG&gt;001166_01w&lt;/STRONG&gt;, in which &lt;STRONG&gt;001166&lt;/STRONG&gt; is gvkey and &lt;STRONG&gt;01w&lt;/STRONG&gt; is iid. In case gviidkey= &lt;STRONG&gt;001166_01&lt;/STRONG&gt;, in which &lt;STRONG&gt;034555&lt;/STRONG&gt; is gvkey and &lt;STRONG&gt;01&lt;/STRONG&gt; is iid.&lt;/P&gt;
&lt;P&gt;It can ben seen from the dataset above is there are some observations that the gviidkey are similar, what I want is select the &lt;STRONG&gt;gviidkey&lt;/STRONG&gt; that its &lt;STRONG&gt;ave_mar_cap&lt;/STRONG&gt; is highest&amp;nbsp; amongst all gviidkey of this gvkey.&lt;/P&gt;
&lt;P&gt;Simplistically speaking, what I want as below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;gviidkey	x1	    x2	    ave_mar_cap
001166_02W	0	    3	    782818024.77
001491_01W	0	    3	    211021885.49
001855_03W	0	    3	    7490455.1517
001932_01W	0	    3	    6966150208.8
002162_01W	0	    3	    2576720.9485
002338_01W	0	    3	    772042538.92
002410_01W	0	    3	    79948092816
002411_03W	0	    3	    84226468905&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If my explaining is not clear, please let me know.&lt;/P&gt;
&lt;P&gt;My novice idea is: create a variable named gvkey, then do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=ave_mar;
  by gvkey;
 var ave_mar_cap;
output out=want max=selected;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I am not sure it is correct or there is any other way to do so as well&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Warm regards.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Mar 2021 12:34:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-the-maximum-of-a-cluster-inside-a-variable/m-p/727074#M226064</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-03-17T12:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to select the maximum of a cluster inside a variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-the-maximum-of-a-cluster-inside-a-variable/m-p/727091#M226069</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212695"&gt;@Phil_NZ&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With PROC SQL you can define the grouping variable as an expression (here: &lt;FONT face="courier new,courier"&gt;substr(gviidkey,1,6)&lt;/FONT&gt;), so you don't need to create a new variable in an intermediate step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select *
from have
group by substr(gviidkey,1,6)
having ave_mar_cap=max(ave_mar_cap);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Mar 2021 12:55:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-the-maximum-of-a-cluster-inside-a-variable/m-p/727091#M226069</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-03-17T12:55:21Z</dc:date>
    </item>
  </channel>
</rss>

