SAS中文论坛

标题: [疑难解惑] 有关MODIFY的问题,总是不能得到想要的结果 [打印本页]

作者: shiyiming    时间: 2012-7-26 15:58
标题: [疑难解惑] 有关MODIFY的问题,总是不能得到想要的结果
请各位大侠帮忙看看。
想将master中,id=2、3、4的数据更新,log中显示已经更新,但实际结果没有。
十分感谢!!!

[color=#4000FF:18s9p2hl]NOTE: There were 5 observations read from the data set WORK.TRANSACTION.
NOTE: The data set WORK.MASTER has been updated.  There were 3 observations rewritten, 2 observations added and 0
      observations deleted.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds[/color:18s9p2hl]

[code:18s9p2hl]DATA master(index=(id));
        INPUT id value;
DATALINES;
1 10
2 20
3 30
4 40
5 50
;
RUN;
DATA transaction;
        INPUT id value;
DATALINES;
2 12
3 13
4 14
6 16
7 17
;
RUN;

data master;
        set transaction;
        modify master key=id;
        select (_iorc_);
                when (%sysrc(_sok)) do;
                        replace;
                end;
                when (%sysrc(_dsenom)) do;
                        _error_=0;
                        output;
                end;
        end;
run;
proc print data=master;run;[/code:18s9p2hl]
作者: shiyiming    时间: 2012-7-26 18:25
标题: Re: [疑难解惑] 有关MODIFY的问题,总是不能得到想要的结果
谢谢各位关注,我已经知道如何在MODIFY中使用REPLACE了。程序调整如下:

[code:1zmcewsq]DATA master(index=(id));
       INPUT id value;
    DATALINES;
    1 10
    2 20
    3 30
    4 40
    5 50
    ;
    RUN;
    DATA transaction;
       INPUT id newvalue;
    DATALINES;
    2 12
    3 13
    4 14
    6 16
    7 17
    ;
    RUN;

    data master;
       set transaction;
       modify master key=id;
       select (_iorc_);
          when (%sysrc(_sok)) do;
                  value=newvalue;
                  replace;
          end;
          when (%sysrc(_dsenom)) do;
             _error_=0;
             value=newvalue;
             output;
          end;
       end;
    run;
    proc print data=master;run;[/code:1zmcewsq]




欢迎光临 SAS中文论坛 (http://www.mysas.net/forum/) Powered by Discuz! X3.2