SAS:当“where"出现时如何不覆盖数据集“修改"中的条件声明不成立? [英] SAS: How not to overwrite a dataset when the "where" condition in a "Modify" statement does not hold?
问题描述
我有以下 SAS 代码:
I have the following SAS code:
data have_1;
modify have_1 have_2(where=(message="X")) updatemode=nomissingcheck;
by reference;
qty=qty-canceled_qty;
if qty=0 then delete;
run;
这是在一个循环内,这意味着对于我的问题,数据集 have_2
每次循环迭代都会发生变化.字段条目 message
更改代码,如X"、A"、B"……消息的到达顺序很重要.这就是为什么我在遍历每个消息序列的循环中工作.have_2
中的每条消息对 have_1
都有不同的含义.消息X"暗示我必须将数量更新为特定参考编号.
This is within a loop and this implies that for my problem the dataset have_2
changes for each loop iteration. The field entry message
changes codes like "X", "A", "B"... the order arrival of messages mater. That is why I work within a loop that goes through the sequences of each message. Each message in have_2
have different implications for have_1
. The message "X" implies that I have to update the quantity to a specific reference number.
因此,鉴于我不知道消息的顺序是什么,我对循环内的每个 message
都有一个 modify
语句.如果在上面的示例中,message
不等于X",我如何避免 SAS 覆盖我的数据集 have_1
?
Therefore, I have a modify
statement for each message
inside the loop given that I don't know what is the order of message. How can I avoid SAS to overwrite my dataset have_1
if, say in the example above, the message
is not equal "X"?
这个问题是我之前的问题的后续问题 >
This question is a follow-up to my previous question
推荐答案
如何避免 SAS 覆盖我的数据集..." - 如果您的意思是在记录级别覆盖 - 检查 _iorc_
值会让你控制做什么.您可以添加自己的逻辑来更新下面的模板代码.不匹配的值为_DSENMR".
"How can I avoid SAS to overwrite my dataset..." - if you mean overwriting on record level - checking _iorc_
value will give you control on what to do. You can add own logic to updates to the template code below.
Value for Not matched is "_DSENMR".
data have_1;
modify have_1 have_2(where=(message="X")) updatemode=nomissingcheck;
by reference;
if _iorc_ = %sysrc(_SOK) then do;
* Update row ;
replace;
end;
else if _iorc_ = %sysrc(_DSENMR) then do;
* Add row ;
output;
_error_ = 0;
end;
else if _iorc_ = %sysrc(_DSEMTR) then do;
* Multiple TRANSACTION data set observations do ;
* not exist in MASTER data set ;
_error_ = 0;
end;
else if _iorc_ = %sysrc(_DSENOM) then do;
* No matching observation was found in MASTER data set ;
_error_ = 0;
end;
run;
在此处查看更多信息 http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/viewer.htm
这篇关于SAS:当“where"出现时如何不覆盖数据集“修改"中的条件声明不成立?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!