如果/ Then / Do语句在SAS中不起作用

时间:2015-07-29 12:52:35

标签: sas

我有一个曾经工作的IF / Then / Do语句,但经过一些修改后它不再有效。我希望满足某个条件,当它满足时,我希望它发送电子邮件。如果不满足,那么我不想要发送电子邮件。代码的电子邮件部分工作正常,事实上,无论条件是否满足,它都会发送电子邮件。我已经多次使用我知道会遇到的数据测试IF / Then / Do语句,但不符合条件。以下是剧本:

    data Hoth;
    IF (Luke = '1' and Darth = '0') then do;
    data _NULL_;
    filename myemail EMAIL
    to="me@lando.com"
    cc="me@lando.com"
    from="me@lando.com"
    subject="Millenium Falcon"
    importance="HIGH";
    file myemail;
    put "Han,";
    put " ";
    put "Look out for the asteroids.";
    put " ";
    put "Thank you.";
    put " ";
    put "Obi";
    run;

1 个答案:

答案 0 :(得分:0)

您应该查看使用电子邮件指令,以允许对您的数据步骤生成的电子邮件进行条件控制。

data Millenium_Falcon;
    han='1';
    luke='0';
    darth='0';
run;

filename myemail EMAIL
    to="me@lando.com"
    cc="me@lando.com"
    from="me@lando.com"
    subject="Millenium Falcon"
    importance="HIGH"
;

data _null_;
    set Millenium_Falcon ;
    file myemail;
    IF (Luke = '1' and Darth = '0') then do;
        put "Han,";
        put " ";
        put "Look out for the asteroids.";
        put " ";
        put "Thank you.";
        put " ";
        put "Obi";
    end;
    else do;
        put '!EM_ABORT!';
    end;
    stop;
run;