【问题标题】:In SAS DS2, how to create a simple program to calculate bmi在SAS DS2中,如何创建一个简单的程序来计算bmi
【发布时间】:2022-01-17 00:20:03
【问题描述】:

我正在尝试通过编写一个计算 BMI 的程序来学习一些基本的 DS2 编程。我编写了一个程序,但我收到“错误:第 47 行:尝试从 void 表达式获取值。”。我做错了什么?

这是我的程序:

    proc ds2;
    data _null_;
    dcl double bmi;

    method bmi_calc(double height, double weight);
        dcl double bmi;
        bmi = weight/(height * height);
    end;

    method init();
      weight = 70.5;
      height = 1.68;
    end;

    method run();
        bmi = bmi_calc(height, weight);
        put 'BMI IS: ' bmi;
    end;

    method term();
        put bmi;
    end;

    enddata;
    run;
   quit;

【问题讨论】:

    标签: sas sas-ds2


    【解决方案1】:

    您需要在 ds2 中使用自定义方法做两件事:

    1. 声明要返回的值的类型
    2. 返回值

    例如,此方法返回值10

    method foo() returns double;
        return 10;
    end;
    

    要使您的方法有效,您只需说明要返回的变量类型,然后返回该值。

    method bmi_calc(double height, double weight) returns double;
        dcl double bmi;
        bmi = weight/(height * height);
        return bmi;
    end;
    

    【讨论】:

    • 谢谢斯图!它工作得很好:)
    猜你喜欢
    • 1970-01-01
    • 2014-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-24
    • 2018-03-03
    • 2022-11-12
    • 1970-01-01
    相关资源
    最近更新 更多