I'm trying to build an advanced system of reporting and logging, and I have a problem.
Example:
work.check_true is empty.
When this table is empty then variable like 'czy_wyslac' should have value 2. If this table not empty, variable 'czy_wyslac' should have value from field "gen" (1 or 0) from table work.check_true. Next step - depending on the value of variable 'czy_wyslac" processing one from three step to next macro. I do not have a problem with this.
Below is my code:
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();
If work.check
is empty, the select gen into :czy_wyslac from work.check_true
will not return anything, thereby retaining any previous value in &CZY_WYSLAC
.
Therefore the below will accomplish what you want :
%LET CZY_WYSLAC = 2 ; /* default value */ proc sql noprint ; select gen into :CZY_WYSLAC from work.check_true ; quit ;