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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 995 views
  • 7 likes
  • 4 in conversation