我最近才開始使用 SAS。我正在嘗試newtable基于另一個表創建一個新表oldtable。假設oldtable包含變數OldPrice。我想創建newtable一個NewPrice基于OldPrice. 然后過濾newtable只顯示NewPrice大于 10 的。
下面是我的示例代碼。
data newtable;
set oldtable;
NewPrice = OldPrice * 2
where NewPrice > 10;
run;
但是,我收到錯誤訊息說這NewPrice不是oldtable.
uj5u.com熱心網友回復:
WHERE 在資料到達資料步驟之前對資料進行操作。要在觀察已經在資料步驟中時有條件地洗掉觀察,您需要使用 IF。
例如,只需使用子集 IF 而不是 WHERE。
data newtable;
set oldtable;
NewPrice = OldPrice * 2;
if NewPrice > 10;
run;
或者明確洗掉您不想要的觀察結果。
data newtable;
set oldtable;
NewPrice = OldPrice * 2;
if NewPrice <= 10 then delete;
run;
uj5u.com熱心網友回復:
甲WHERE陳述句運算式僅可以在來自所述節目資料矢量(PDV)使用變數SET宣告。
資料集選項WHERE=可用于指定輸入或輸出資料集。
陳述
資料要; 設定有; 其中運算式; ...
選項
資料要; 設定有(where=(運算式)); ...
或者
資料需要(where=(運算式)); 設定有; ...
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/405242.html
標籤:
