do 在宏内循环

发布于 2025-01-17 20:48:18 字数 337 浏览 1 评论 0原文

下面的代码返回以下错误消息:

语法错误,需要以下之一:名称、INPUT、PUT。

%macro run_calculation(amt, t, r);
    data customer_value;
    i=&r./100.; 
    do n=0 to t;
    S=&amt.*[(1+ calculated i)^t - 1]/calculated i
    end;
    run;
%mend;


%run_calculation(amt=1000, t=8, r=5);

预期输出是表中每个 t 的 S 值。

The code below is returning the following error message:

Syntax error, expecting one of the following: a name, INPUT, PUT.

%macro run_calculation(amt, t, r);
    data customer_value;
    i=&r./100.; 
    do n=0 to t;
    S=&amt.*[(1+ calculated i)^t - 1]/calculated i
    end;
    run;
%mend;


%run_calculation(amt=1000, t=8, r=5);

Expected output is S value at each t in a table.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不即不离 2025-01-24 20:48:18

很少有评论:

  • 分配S时缺少半柱;
  • 您不必直接使用直接使用 i 。
  • SAS中的电源运算符为**,而不是^
  • 您指出t,而不是do loop语句中的宏观变量& t。
  • 您会增加n,而不是t,因此您需要在公式中使用n
  • 使用括号,而不是括号。
  • 您缺少明确的输出语句,以获取每个n的s值。
%macro run_calculation(amt, t, r);
    data customer_value;
        i=&r./100.;
        do n=0 to &t.;
            S=&amt.*((1+i)**n - 1)/i;
            output;
        end;
    run;
%mend;

%run_calculation(amt=1000, t=8, r=5);
  i   n    S
 0.05 0 0
 0.05 1 1000
 0.05 2 2050
 0.05 3 3152.5
 0.05 4 4310.125
 0.05 5 5525.63125
 0.05 6 6801.9128125
 0.05 7 8142.0084531
 0.05 8 9549.1088758

Few comments:

  • You are missing a semi-colon ; when assigning S.
  • You don't have to use calculated i, use i directly.
  • Power operator in SAS is ** and not ^.
  • You point to t instead of the macro-variable &t. in the do loop statement.
  • You increment n, not t so you need to use n in your formula.
  • Use parenthesis, not brackets.
  • You are missing an explicit output statement in order to get S value for each n.
%macro run_calculation(amt, t, r);
    data customer_value;
        i=&r./100.;
        do n=0 to &t.;
            S=&amt.*((1+i)**n - 1)/i;
            output;
        end;
    run;
%mend;

%run_calculation(amt=1000, t=8, r=5);
  i   n    S
 0.05 0 0
 0.05 1 1000
 0.05 2 2050
 0.05 3 3152.5
 0.05 4 4310.125
 0.05 5 5525.63125
 0.05 6 6801.9128125
 0.05 7 8142.0084531
 0.05 8 9549.1088758
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文