turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- How to get summary value of A field based on the m...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-08-2014 05:17 AM

Dear All,

Assume, there are a dataset. The dataset name is my_data, there are 3 fields:term, financed amount, interes_rate.

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.

Now, I use two PROC MEANS to finish the job.

could you I just use only one PROC MEANS to do that?

Thanks.

Accepted Solutions

Solution

11-09-2014
09:26 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-09-2014 09:26 PM

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.

If you post sample data I can post sample code.

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-08-2014 06:39 AM

Sure.

by term ;

var interest_rate ;

output out=want min=min sum=sum

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-09-2014 01:20 AM

thx. but it is not what do i want.

for each term, how to get sum of financed amount that according interest rate is the lowest rate.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-09-2014 03:49 AM

i believe we could achieve the output you are expecting, but we need to process the data before using proc means,

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,

Try

data have;

input term interest amount;

datalines;

1991 10 20000

1991 10 20000

1991 10 20000

1991 20 30000

1991 15 25000

;

run;

proc sort data = have;

by term interest;

run;

data have2;

set have;

retain min;

by term interest;

if first.term then min= interest;

run;

proc means data=have2(where=(interest=min));

by term ;

var amount;

output out = want sum=sum;

run;

Thanks,

Jag

Thanks,

Jag

Jag

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-09-2014 08:06 AM

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.

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 term,interest,sum(amount) as sum_amount from (select * from have group by term having interest=min(interest)) group by term,interest; quit;

Xia Keshan

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-09-2014 08:57 AM

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.

Solution

11-09-2014
09:26 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-09-2014 09:26 PM

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.

If you post sample data I can post sample code.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-16-2014 10:59 PM

Dear Reeza,

Thx. I will try to do by mysefl based on your suggestion.

Best Regards,

Liu ming