<?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: How to get summary value of A field based on the min value of B field in same PROC MEANS? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-get-summary-value-of-A-field-based-on-the-min-value-of-B/m-p/162632#M42243</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i believe we could achieve the output you are expecting, but we need to process the data before using proc means,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;first we need to create a variable, which stores the min interest rate for each term and retains the same value across all records for that term. Then subset the data on the min interest rate records and pass the same in proc means to get the sum, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input term interest amount;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1991 10 20000&lt;/P&gt;&lt;P&gt;1991 10 20000&lt;/P&gt;&lt;P&gt;1991 10 20000&lt;/P&gt;&lt;P&gt;1991 20 30000&lt;/P&gt;&lt;P&gt;1991 15 25000&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 sort data = have;&lt;/P&gt;&lt;P&gt;by&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; term interest; &lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;retain min;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by&amp;nbsp; term interest; &lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.term then min= interest;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc means data=have2(where=(interest=min));&lt;/P&gt;&lt;P&gt;by term ;&lt;/P&gt;&lt;P&gt;var amount;&lt;/P&gt;&lt;P&gt;output out = want sum=sum;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jag&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 09 Nov 2014 08:49:24 GMT</pubDate>
    <dc:creator>Jagadishkatam</dc:creator>
    <dc:date>2014-11-09T08:49:24Z</dc:date>
    <item>
      <title>How to get summary value of A field based on the min value of B field in same PROC MEANS?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-get-summary-value-of-A-field-based-on-the-min-value-of-B/m-p/162629#M42240</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Assume, there are a dataset. The dataset name is my_data, there are 3 fields:term, financed amount, interes_rate.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My purposes are calculate the min interest_rate per term. And, calculate the sum of financed amount for that term's interest rate is min value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now, I use two PROC MEANS to finish the job.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;could you I just use only one PROC MEANS to do that?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Nov 2014 10:17:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-get-summary-value-of-A-field-based-on-the-min-value-of-B/m-p/162629#M42240</guid>
      <dc:creator>LiuMing</dc:creator>
      <dc:date>2014-11-08T10:17:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to get summary value of A field based on the min value of B field in same PROC MEANS?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-get-summary-value-of-A-field-based-on-the-min-value-of-B/m-p/162630#M42241</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sure.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;by &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12.727272033691406px; background-color: #ffffff;"&gt;term&lt;/SPAN&gt; ;&lt;/P&gt;&lt;P&gt;var &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12.727272033691406px; background-color: #ffffff;"&gt;interest_rate &lt;/SPAN&gt;;&lt;/P&gt;&lt;P&gt;output out=want&amp;nbsp; min=min sum=sum&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Nov 2014 11:39:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-get-summary-value-of-A-field-based-on-the-min-value-of-B/m-p/162630#M42241</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-11-08T11:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to get summary value of A field based on the min value of B field in same PROC MEANS?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-get-summary-value-of-A-field-based-on-the-min-value-of-B/m-p/162631#M42242</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thx. but it is not what do i want.&lt;/P&gt;&lt;P&gt;for each term, how to get sum of financed amount that according interest rate is the lowest rate.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Nov 2014 06:20:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-get-summary-value-of-A-field-based-on-the-min-value-of-B/m-p/162631#M42242</guid>
      <dc:creator>LiuMing</dc:creator>
      <dc:date>2014-11-09T06:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to get summary value of A field based on the min value of B field in same PROC MEANS?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-get-summary-value-of-A-field-based-on-the-min-value-of-B/m-p/162632#M42243</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i believe we could achieve the output you are expecting, but we need to process the data before using proc means,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;first we need to create a variable, which stores the min interest rate for each term and retains the same value across all records for that term. Then subset the data on the min interest rate records and pass the same in proc means to get the sum, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input term interest amount;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1991 10 20000&lt;/P&gt;&lt;P&gt;1991 10 20000&lt;/P&gt;&lt;P&gt;1991 10 20000&lt;/P&gt;&lt;P&gt;1991 20 30000&lt;/P&gt;&lt;P&gt;1991 15 25000&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 sort data = have;&lt;/P&gt;&lt;P&gt;by&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; term interest; &lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;retain min;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by&amp;nbsp; term interest; &lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.term then min= interest;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc means data=have2(where=(interest=min));&lt;/P&gt;&lt;P&gt;by term ;&lt;/P&gt;&lt;P&gt;var amount;&lt;/P&gt;&lt;P&gt;output out = want sum=sum;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jag&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Nov 2014 08:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-get-summary-value-of-A-field-based-on-the-min-value-of-B/m-p/162632#M42243</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2014-11-09T08:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to get summary value of A field based on the min value of B field in same PROC MEANS?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-get-summary-value-of-A-field-based-on-the-min-value-of-B/m-p/162633#M42244</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As Jag pointed out, you need to post some dummy data to clarify your question. It is not possible for one proc means ,but easy for proc sql.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;


data have;
input term interest amount;
datalines;
1991 10 20000
1991 10 20000
1991 10 20000
1991 20 30000
1991 15 25000
;
run;
proc sql;
create table want as
 select&amp;nbsp; term,interest,sum(amount) as sum_amount
 from (select * from have group by term having interest=min(interest))
&amp;nbsp; group by term,interest;
quit;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&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, 09 Nov 2014 13:06:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-get-summary-value-of-A-field-based-on-the-min-value-of-B/m-p/162633#M42244</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-11-09T13:06:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to get summary value of A field based on the min value of B field in same PROC MEANS?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-get-summary-value-of-A-field-based-on-the-min-value-of-B/m-p/162634#M42245</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thx everyone. actually, now, i done that with what your suggestion. i use two separate step. i just want to know whether there are more sas style solution.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Nov 2014 13:57:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-get-summary-value-of-A-field-based-on-the-min-value-of-B/m-p/162634#M42245</guid>
      <dc:creator>LiuMing</dc:creator>
      <dc:date>2014-11-09T13:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to get summary value of A field based on the min value of B field in same PROC MEANS?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-get-summary-value-of-A-field-based-on-the-min-value-of-B/m-p/162635#M42246</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could use the ways/type statement to generate all combination and then only keep the ones you want using a where statement in a single proc means. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you post sample data I can post sample code. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Nov 2014 02:26:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-get-summary-value-of-A-field-based-on-the-min-value-of-B/m-p/162635#M42246</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-11-10T02:26:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to get summary value of A field based on the min value of B field in same PROC MEANS?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-get-summary-value-of-A-field-based-on-the-min-value-of-B/m-p/162636#M42247</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Reeza,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thx. I will try to do by mysefl based on your suggestion.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Liu ming&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Nov 2014 03:59:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-get-summary-value-of-A-field-based-on-the-min-value-of-B/m-p/162636#M42247</guid>
      <dc:creator>LiuMing</dc:creator>
      <dc:date>2014-11-17T03:59:56Z</dc:date>
    </item>
  </channel>
</rss>

