SAS:无法在数据集中添加变量

发布于 2025-02-06 01:33:39 字数 427 浏览 3 评论 0原文

我有一个数据集,并且正在尝试使用现有的数据集添加四个新变量。我一直遇到一个错误,说代码不完整。我很难看到它不完整的地方。我该如何解决?

data dataset;
 input  ID $
        Height 
        Weight 
        SBP 
        DBP 
        WtKg         = Weight/2.2;
        HtCm         =  Height/2.4;
        AveBP        = DBP + (SBP - DBP)/3;
        HtPolynomial = (2*Height)**2 + (1.5*Height)**3;
 
datalines;
001 68 150 110 70
002 73 240 150 90
003 62 101 120 80
run;

I have a data set and am trying to add four new variables using the existing ones. I keep getting an error that says the code is incomplete. I'm having trouble seeing where it is incomplete. How do I fix this?

data dataset;
 input  ID $
        Height 
        Weight 
        SBP 
        DBP 
        WtKg         = Weight/2.2;
        HtCm         =  Height/2.4;
        AveBP        = DBP + (SBP - DBP)/3;
        HtPolynomial = (2*Height)**2 + (1.5*Height)**3;
 
datalines;
001 68 150 110 70
002 73 240 150 90
003 62 101 120 80
run;

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

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

发布评论

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

评论(2

╰沐子 2025-02-13 01:33:39

您没有用半隆结束输入语句。 输入从外部数据读取变量(在这种情况下,使用Datalines语句的在线数据)。在您指定的方式中,并未在输入中创建新变量。

使用输入在数据的五个变量中读取。之后,根据这五个读取变量创建新变量:

data dataset;
    input  ID $
           Height 
           Weight 
           SBP 
           DBP
    ; 

    WtKg         = Weight/2.2;
    HtCm         = Height/2.4;
    AveBP        = DBP + (SBP - DBP)/3;
    HtPolynomial = (2*Height)**2 + (1.5*Height)**3;
 
    datalines;
001 68 150 110 70
002 73 240 150 90
003 62 101 120 80
;
run;

You did not end your input statement with a semicolon. input reads variables from external data (in this case, in-line data with the datalines statement). New variables are not created within input in the way you've specified.

Use input to read in the five variables of your data. After that, create new variables based on those five read-in variables:

data dataset;
    input  ID $
           Height 
           Weight 
           SBP 
           DBP
    ; 

    WtKg         = Weight/2.2;
    HtCm         = Height/2.4;
    AveBP        = DBP + (SBP - DBP)/3;
    HtPolynomial = (2*Height)**2 + (1.5*Height)**3;
 
    datalines;
001 68 150 110 70
002 73 240 150 90
003 62 101 120 80
;
run;
末骤雨初歇 2025-02-13 01:33:39

纠正2个错误应解决以下问题:

  1. 从数据读物中读取最后一个字段后,添加一个半隆(即DBP。

  2. (此问题的先前版本使用了指数的 ^符号。)而不是 ^提高某物的力量,而是使用**

    为参考,描述了SAS算术运算符

在上面进行2个校正后,我在下面进行了修订的代码,没有任何错误。

data dataset;
 input  ID $
        Height 
        Weight 
        SBP 
        DBP; 
        WtKg         = Weight/2.2;
        HtCm         =  Height/2.4;
        AveBP        = DBP + (SBP - DBP)/3;
        HtPolynomial = (2*Height)**2 + (1.5*Height)**3;
 
datalines;
001 68 150 110 70
002 73 240 150 90
003 62 101 120 80
run;

Correcting 2 errors should fix this:

  1. Add a semicolon after the last field being read in from the datalines, which is DBP.

  2. (A previous version of this question used the ^ symbol for exponents.) Instead of ^ to raise to the power of something, use **

    For reference, SAS arithmetic operators are described here.

After making the 2 corrections above I ran the revised code below without any errors.

data dataset;
 input  ID $
        Height 
        Weight 
        SBP 
        DBP; 
        WtKg         = Weight/2.2;
        HtCm         =  Height/2.4;
        AveBP        = DBP + (SBP - DBP)/3;
        HtPolynomial = (2*Height)**2 + (1.5*Height)**3;
 
datalines;
001 68 150 110 70
002 73 240 150 90
003 62 101 120 80
run;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文