多个设置为宏变量

时间:2018-09-27 16:58:59

标签: sas sas-macro

我正在尝试构建高级的报告和日志记录系统,但是我遇到了问题。

示例:

work.check_true为空。

此表为空时,则变量'czy_wyslac'应该具有值2。 如果该表不为空,则变量'czy_wyslac'应该具有表work.check_true中字段“ gen”(1或0)中的值。 下一步-根据变量'czy_wyslac'的值处理从三步到下一宏的操作。我对此没有问题。

下面是我的代码:

data _null_;
call symput('obscnt',0);
set work.Check_true;
call symput('obscnt',_n_);
stop;
run;

%macro get_table_size();
%global czy_wyslac;
%If &obscnt=0 %then call SYMPUTX('czy_wyslac',2);

%else
    proc sql noprint;
    select
        gen into: czy_wyslac
    from work.Check_true
    ;quit;
%mend;


%macro Create_log_mail();

   %if &czy_wyslac. = 1 %then
    %do;
        data work.maile;
        zal = "T:\XXX\XXX\Risk\XXXX\XXXX\OUTPUT\Results_of_compare &calosc..xlsx";
        run;

        options emailsys=XXemail host=XXXemailport=XXX;

        FILENAME mail EMAIL;

        DATA _NULL_;
        SET WORK.maile END=eof;
        FILE mail ENCODING='UTF-8';
        PUT '!EM_TO! "XXXXX@XXXXXX"';
        PUT 'Szanowni,';
        PUT 'Załącznik zawiera znalezione różnice między szablonem kalkulatora a zawartym w systemie ATP.';
        PUT 'Wpis _TYPE> = PLIK - baza porównywana';
        PUT 'Wpis _TYPE> = ATP - rekord wyciągnięty z ATP';
        PUT;
        PUT 'Baza zawiera również wynik porównania wyposażenia oraz baseline.';
        PUT;
        PUT 'Pozdrawiam,';
        PUT 'KJ SYSTEM REPORT';
        PUT '!EM_FROM! XXXSYSTEM REPORT <noreply@XXXXX.pl>';
        PUT '!EM_SENDER! XXXXSYSTEM REPORT <noreply@XXXX.pl>';
        PUT '!EM_BCC! ';
        PUT '!EM_SUBJECT! XXXXXXXX';
        PUT '!EM_ATTACH!' zal;
        PUT '!EM_REPLYTO! Please do not reply for this mail - regards :)';
        PUT '!EM_SEND!' / '!EM_NEWMSG!';
        IF eof THEN PUT '!EM_ABORT!';
        RUN;

            proc sql;
            Create table LOG_CREATE as
            Select
            distinct
            date()*86400 format datetime20. as EXTRACT_DATE,
            date()*86400 format datetime20. as REFERENCE_DATE,
            'MAIL: Results_of_compare' as STAGE_NAME,
            '99_02_MAIL_RESULT' as PROCES_NAME,
            '02_CALCULATOR_ATP' as SCHEMA_NAME,
            20 as etap_no,
            'SENT' as STATUS,
            &Count_records_02. as records,
            'Wysłano mail' as Comments,
            . as alert_records,
            '' as Alert_comments,
            &_timer_start format datetime20. as START_PROCESS,
            datetime() format datetime20. as END_PROCESS,
            datetime() - &_timer_start format time13.2 as Duration
            FROM work._PRODSAVAIL
            ;quit;
    %end;

    %else %if &czy_wyslac. = 0 %then %do;
        proc sql;
        Create table LOG_CREATE as
        Select
        distinct
        date()*86400 format datetime20. as EXTRACT_DATE,
        date()*86400 format datetime20. as REFERENCE_DATE,
        'MAIL: Results_of_compare' as STAGE_NAME,
        '99_02_MAIL_RESULT' as PROCES_NAME,
        '02_CALCULATOR_ATP' as SCHEMA_NAME,
        20 as etap_no,
        'NOT SENT' as STATUS,
        . as records,
        '' as Comments,
        . as alert_records,
        '' as Alert_comments,
        &_timer_start format datetime20. as START_PROCESS,
        datetime() format datetime20. as END_PROCESS,
        datetime() - &_timer_start format time13.2 as Duration
        FROM work._PRODSAVAIL
        ;quit;
    %end;
%mend;
%Create_log_mail();

1 个答案:

答案 0 :(得分:2)

如果work.check为空,则select gen into :czy_wyslac from work.check_true将不返回任何内容,从而保留&CZY_WYSLAC中的所有先前值。

因此,以下内容将满足您的要求:

%LET CZY_WYSLAC = 2 ; /* default value */
proc sql noprint ;
  select gen into :CZY_WYSLAC from work.check_true ;
quit ;