BookmarkSubscribeRSS Feed
pp2014
Fluorite | Level 6

I am using the following code to send email through SAS if any of the datasets(daily)  are missing after checking if it is a working day or not based on the working day dataset.  Everything works but  it sends email  also even if wday_cnt = 0 (means non-working day).  Can anybody let me know what I am doing wrong..

proc sql noprint;  

/** check if it is a working day or not *************/

  select count(new_date) into :wday_cnt 

   from  wday_dsn

    where  date1 = today();

  /***** Check if  dsn2 data  exists for today or not **************/

  select count(distinct var1) into :dsn1_var_cnt 

   from  dsn1

    where dsn1_date = today();

/***** Check if dsn2 data exists for today or not **************/

  select count(distinct var1) into :dsn2_var_cnt 

   from dsn2

    where dsn2_date = today();

quit;

%put wday_cnt=&wday_cnt.;

%put dsn1_var_cnt =&dsn1_var_cnt.;

%put dsn2_var_cnt=&dsn2_var_cnt.;

   filename mail email from="myname@email.com"; 

data _null_;

   if &wday_cnt. = 1  then do; 

   if &dsn1_var_cnt. = 0  and &dsn2_var_cnt. > 0 then do;    

    file mail  

    to=("myname@email.com")

      cc=("xyz@email.com" "abc@email.com")

  subject="Report Alert";

     put " DSN1 data missing"; end;

   if &dsn1_var_cnt. > 0  and &dsn2_var_cnt. = 0 then do;   

    file mail

    to=("myname@email.com")

  cc=("xyz@email.com" "abc@email.com")

  subject="Report Alert";

     put " DSN2 data missing"; end;

   if &dsn1_var_cnt. = 0  and &dsn2_var_cnt. = 0 then do;   

    file mail 

    to=("myname@email.com")

   cc=("xyz@email.com" "abc@email.com")

  subject="Report Alert";

     put " DSN1 and DSN2 data missing"; end;

  end;   /****** Working day loop end ***********/ 

run;

6 REPLIES 6
pp2014
Fluorite | Level 6

Can anybody help me??

Amir
PROC Star

Hi,

What happens if you put it into a macro, e.g.:

%macro testmail;

   %if &wday_cnt. = 1  %then %do;

   filename mail email from="myname@email.com";

data _null_;

   if &dsn1_var_cnt. = 0  and &dsn2_var_cnt. > 0 then do;   

    file mail 

    to=("myname@email.com")

      cc=("xyz@email.com" "abc@email.com")

  subject="Report Alert";

     put " DSN1 data missing"; end;

   if &dsn1_var_cnt. > 0  and &dsn2_var_cnt. = 0 then do;  

    file mail

    to=("myname@email.com")

  cc=("xyz@email.com" "abc@email.com")

  subject="Report Alert";

     put " DSN2 data missing"; end;

   if &dsn1_var_cnt. = 0  and &dsn2_var_cnt. = 0 then do;  

    file mail

    to=("myname@email.com")

   cc=("xyz@email.com" "abc@email.com")

  subject="Report Alert";

     put " DSN1 and DSN2 data missing"; end;

run;

  %end;   /****** Working day loop end ***********/

%mend testmail;

%testmail;

Regards,

Amir.

Message was edited by: Amir - added macro call.

pp2014
Fluorite | Level 6

Thanks Amir for help.  Yes,  macro did the trick

pp2014
Fluorite | Level 6

I get the email notification also with just subject ="Report Alert"   if  &wday_cnt = 1  and  &dsn1_var_cnt > 0  and  &dsn2_var_cnt.  I  do not want this email notification. please help

proc sql noprint; 

/** check if it is a working day or not *************/

  select count(new_date) into :wday_cnt

   from  wday_dsn

    where  date1 = today();

  /***** Check if  dsn2 data  exists for today or not **************/

  select count(distinct var1) into :dsn1_var_cnt

   from  dsn1

    where dsn1_date = today();

/***** Check if dsn2 data exists for today or not **************/

  select count(distinct var1) into :dsn2_var_cnt

   from dsn2

    where dsn2_date = today();

quit;

%put wday_cnt=&wday_cnt.;

%put dsn1_var_cnt =&dsn1_var_cnt.;

%put dsn2_var_cnt=&dsn2_var_cnt.;

%macro testmail;

   %if &wday_cnt. = 1  %then %do;

   filename mail email from="myname@email.com";

data _null_;

   if &dsn1_var_cnt. = 0  and &dsn2_var_cnt. > 0 then do;  

    file mail

    to=("myname@email.com")

      cc=("xyz@email.com" "abc@email.com")

  subject="Report Alert";

     put " DSN1 data missing"; end;

   if &dsn1_var_cnt. > 0  and &dsn2_var_cnt. = 0 then do; 

    file mail

    to=("myname@email.com")

  cc=("xyz@email.com" "abc@email.com")

  subject="Report Alert";

     put " DSN2 data missing"; end;

   if &dsn1_var_cnt. = 0  and &dsn2_var_cnt. = 0 then do; 

    file mail

    to=("myname@email.com")

   cc=("xyz@email.com" "abc@email.com")

  subject="Report Alert";

     put " DSN1 and DSN2 data missing"; end;

run;

  %end;   /****** Working day loop end ***********/

%mend testmail;


%testmail;

pp2014
Fluorite | Level 6

Anybody know how this can be resolved..

pp2014
Fluorite | Level 6

I resolved it.

I used the following condition in the loop

%if &wday_cnt. = 1 and (&dsn1_var_cnt. = 0  or &dsn2_var_cnt. = 0) %then %do;


%end;

sas-innovate-2024.png

Today is the last day to save with the early bird rate! Register today for just $695 - $100 off the standard rate.

 

Plus, pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 902 views
  • 0 likes
  • 2 in conversation