我如何构建一个 sas do 循环来获取剩余要支付的金额?

how do i construct a sas do loop to get the amount of what's left to be paid?

希望你能帮助我。

下面的table想用sas代码展示我想得到的结果。 基本上就是计算分期付款的金额,从par_value10.000€开始,10年6%的利率,每期结束时固定分期付款。

year fixed_installment interests capital_paid loan_paid to_be_paid
1 1.358,68 € 600,00 € 758,68 € 758,68 € 9.241,32 €
2 1.358,68 € 554,48 € 804,20 € 1.562,88 € 8.437,12 €
3 1.358,68 € 506,23 € 852,45 € 2.415,33 € 7.584,67 €
4 1.358,68 € 455,08 € 903,60 € 3.318,93 € 6.681,07 €
5 1.358,68 € 400,86 € 957,82 € 4.276,75 € 5.723,25 €
6 1.358,68 € 343,40 € 1.015,28 € 5.292,03 € 4.707,97 €
7 1.358,68 € 282,48 € 1.076,20 € 6.368,23 € 3.631,77 €
8 1.358,68 € 217,91 € 1.140,77 € 7.509,01 € 2.490,99 €
9 1.358,68 € 149,46 € 1.209,22 € 8.718,23 € 1.281,77 €
10 1.358,68 € 76,91 € 1.281,77 € 10.000,00 € 0,00 €

利息是按par_value;

乘以6%的利率得到的

capital_paid 是给定年份的分期付款与支付的利息之间的差额。

loan_paid是每年支付的资本部分的总和。

to_be_paid是给定年份的应付资本减去capital_paid的差额(第一行第一年的值是10000-1358,68)。

你尝试了什么?

我可以这样提议:

data test;
    attrib year par_value fixed_installment interest_rate interest capital_paid loan_paid to_be_paid format=best.;
    
    *-- Initial values --*;
    par_value = 10000;  
    fixed_installment = 1358.68;
    interest_rate = 0.06;
    loan_paid = 0;
    
    *-- Loop through 10 years --*;
    do year = 1 to 10;
        *-- Calculate interests --*;
        interest = round((par_value - loan_paid) * interest_rate, 0.01);
        
        *-- Calculate capital paid --*;
        capital_paid = fixed_installment - interest;
        
        *-- Calculate loan paid --*;
        loan_paid = loan_paid + capital_paid;
        
        *-- Calculate remaining loan --*;
        to_be_paid = par_value - loan_paid;
        
        output;
    end;
run;