【问题标题】:Missing output values with different if condition for a particular variable缺少特定变量的不同 if 条件的输出值
【发布时间】:2017-08-06 08:59:26
【问题描述】:
data tt;
input init $ ht wt sex $ time @@;
if ht=. then short=' ';
else if ht<170 then short='y';
else short='n';
if wt=. then heavy=' ';
else if wt<80 then heavy='y';
else wt='n';
cards;
qqq 160.4 60.3 m 1 ewe 167.4 81.5 f 3 aqw 168.0 79.34 f 6
ccc 181.4 87.7 m 19 
;run;

proc print data=tt;
run;





output s like  this
init ht     wt    sex time short heavy
qqq  160.4  60.3  m   1    y     y 
ewe  167.4  .     f   3    y
aqw  168.0  79.34 f   6    y     y     
ccc  181.4  .     m   19   y`

我不知道为什么wt 缺少值。当我把if wt&gt;80 然后wt(60.3 and 79.34) 将丢失,81.587.7 将显示在输出中。

【问题讨论】:

  • 我认为你的最后一行也应该显示“n”代表“short”。我不知道用什么语言来回答,但指出这一点,因为您似乎忽略了这一点。

标签: if-statement sas missing-data


【解决方案1】:

当您查看日志时,是否有一条说明“创建了缺失值....”,并且可能是关于尝试将字符值转换为数值失败的警告或错误?

注意第二个 IF 块的 ELSE 语句:

if wt=. then heavy=' ';
else if wt<80 then heavy='y';
else wt='n';

应该是else heavy='n';。正如所写,它试图将字符值“n”分配给数值变量 wt。 SAS 将尝试将“n”转换为数值,如果失败,它将向日志抛出警告或错误,并将其转换为数值缺失值。

【讨论】:

    猜你喜欢
    • 2017-10-01
    • 1970-01-01
    • 2013-07-14
    • 2011-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多