2017-08-06 47 views
0
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>80 時,wt(60.3 and 79.34)將會丟失,並且81.587.7將顯示在輸出中。如果特定變量條件不同,缺少輸出值

+0

你的最後一行也應該顯示「n」表示「short」,我認爲。我不知道要回答的語言,但指出,因爲看起來你可能忽略了這一點。 – pinkfloydx33

回答

0

當你看日誌時,是否有一個註釋說「缺少的值已創建....」,並可能是關於嘗試將字符值轉換爲數值失敗的警告或錯誤?

注意你的第二個的ELSE語句IF塊:

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

應該else heavy='n';。正如所寫的,它試圖將字符值'n'賦予數字變量wt。 SAS會嘗試將'n'轉換爲數字值,如果失敗則會向日志發出警告或錯誤並將其轉換爲數字缺失值。