在SAS中创建虚拟变量时,有关小数规范的错误

发布于 2025-02-02 16:58:36 字数 415 浏览 3 评论 0原文

我是SAS的新手,想创建一个简单的虚拟变量(男性),该变量等于1,如果sex = 1,则等于0,如果sex = 2 <2 /代码>。但是,我收到错误消息:错误:2的小数规范必须小于1。

我如何解决此问题的宽度规范?这是我使用的代码:

DATA WORK.BMI_D ;
  SET WORK.BMI ;

  IF SEX = 1 THEN MALE = 1; 
    ELSE MALE = 0;
RUN;

变量性爱具有长度8,type 数字和格式f8.2。我在做什么错?

I am very new to SAS and want to create a simple dummy variable (MALE) that equals 1 if SEX = 1, and equals 0 if SEX = 2. However, I get error messages: ERROR: The decimal specification of 2 must be less than the width specification of 1.

How do I solve this? This is the code I use:

DATA WORK.BMI_D ;
  SET WORK.BMI ;

  IF SEX = 1 THEN MALE = 1; 
    ELSE MALE = 0;
RUN;

The variable SEX has length 8, type Numeric and format F8.2. What am I doing wrong?

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

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

发布评论

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

评论(1

哥,最终变帅啦 2025-02-09 16:58:36

您尚未显示出生成该错误消息的代码,但为什么不只是删除您已附加到可变性别的不合逻辑格式。也许该错误是从稍后的步骤中尝试显示性别的宽度仅为1个字节,并且在显示字符串之类的字符串之类格式将产生。

由于不需要使用特殊的显示格式来为1和2的数字值2,只需从性别中删除格式,然后看看是否解决了问题。

DATA WORK.BMI_D ;
  SET WORK.BMI ;

  IF SEX = 1 THEN MALE = 1; 
  ELSE MALE = 0;

  format sex ;
RUN;

You have not showed the code that is generating that error message but why not just remove the illogical format that you have attached to the variable SEX. Perhaps the error is from later step that is trying to display SEX with a width of only 1 byte and is having trouble display the strings like 1.00 or 2.00 that the F8.2 format would generate.

Since there is no need to use a special display format for numeric values of 1 and 2 just remove the format from SEX and see if that solves the issue.

DATA WORK.BMI_D ;
  SET WORK.BMI ;

  IF SEX = 1 THEN MALE = 1; 
  ELSE MALE = 0;

  format sex ;
RUN;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文