BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
LiuMing
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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.

View solution in original post

7 REPLIES 7
Ksharp
Super User

Sure.

by term ;

var interest_rate ;

output out=want  min=min sum=sum

LiuMing
Calcite | Level 5

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.

Jagadishkatam
Amethyst | Level 16

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
Ksharp
Super User

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

LiuMing
Calcite | Level 5

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.

Reeza
Super User

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.

LiuMing
Calcite | Level 5

Dear Reeza,

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

Best Regards,

Liu ming

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1022 views
  • 7 likes
  • 4 in conversation