0

我试图让我的循环和输出语句变得有点方便,目前我有一笔贷款,它像这样摊销:

data have;
input Payment2017 Payment2018 Payment2019 Payment2020;
datalines;

100 10 10 10;

run;

我正在尝试创建一个看起来像这样的成熟度和重新发行配置文件,我将在提交当前代码时解释逻辑:

data want;
input;
P2017 P2018 P2019 P2020 F1 F2 F3 MP2017 MP2018 MP2019 MP2020 NI2017 NI2018 NI2019 NI2020;
datalines;

100 10 10 10 0.1 0.1 0.1 100 10 10 10 0 0 0 0
100 10 10 10 0.1 0.1 0.1 0 10 1 1 0 10 0 0
100 10 10 10 0.1 0.1 0.1 0 0 11 1.1 0 0 11 0
100 10 10 10 0.1 0.1 0.1 0 0 0 12.1 0 0 0 12.1
;
run;

所以逻辑是:

Payment2017 = 年初余额 Payment2018 - 2020 = 每期支付的金额 F1-F3 是每期支付的贷款比例。

MP2017-MP2020 是偿还的贷款金额 - 本质上是

mp(i) = p(i) *f(i) 

NI2017-NI2020 是新发行的金额,如果您假设每次我还清一点贷款,它就会重新添加到贷款中。所以我正在使用的当前代码看起来像这样,但我在输出和循环方面遇到了一些问题。

        data want;
        set have;

        array MaturityProfile(4) MaturityProfile&StartDate-MaturityProfile&EndDate;  
        array NewIssuance(4) NewIssuance&StartDate - NewIssuance&EndDate;
        array p(4) payment&StartDate-payment&EndDate;
        array fraction(3); * track constant fraction determined at start of profile;

            MaturityProfile(1) = P(1);

            do i = 1 to 3;

            fraction(i) = p(i+1) / p(1);

            end;

            iter=2;
            do j = 1 to 2;
            do i = iter to 4;

            MaturityProfile(i) = P(j) * Fraction(i-j);
            newissuance(i) = MaturityProfile(i);
            end;
            output;
            iter=iter+1;
            end;
            output;

            *MaturityProfile(4) = ( P(3) + MaturityProfile(2) ) * Fraction(1);


            *output;

            drop i;
            drop j;
            drop iter;

            run;

我正在尝试为前两行找到一种方法,使其保持当前的输出方式,但第三行需要第二行(或 newissuance2019)的列的总和,然后将其乘以分数 1

所以基本上输出看起来像我在数据需要步骤中放入的表。

TIA。

4

1 回答 1

-1

我设法通过这样做来解决这个问题:

data want;
    set have;

    array MaturityProfile(4) MaturityProfile&StartDate-MaturityProfile&EndDate;  
    array NewIssuance(4) NewIssuance&StartDate - NewIssuance&EndDate;
    array p(4) payment&StartDate-payment&EndDate;
    array fraction(3); * track constant fraction determined at start of profile;
    array Total(4) Total1-Total4;

        MaturityProfile(1) = P(1);

        do i = 1 to 3;

        fraction(i) = p(i+1) / p(1);

        end;

        iter=2;
        do j = 1 to 2;
        do i = iter to 4;

        MaturityProfile(i) = P(j) * Fraction(i-j);
        Total(i)=MaturityProfile(i) + P(i);
        end;
        output;
        iter=iter+1;
        end;

        MaturityProfile(4) = Total(3) * Fraction(1);


        output;

        drop i;
        drop j;
        drop iter;

        run;
于 2018-03-27T08:22:00.643 回答