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.
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.
Sure.
by term ;
var interest_rate ;
output out=want min=min sum=sum
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.
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
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
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.
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.
Dear Reeza,
Thx. I will try to do by mysefl based on your suggestion.
Best Regards,
Liu ming
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.