BookmarkSubscribeRSS Feed
pradeep_kadasi
Fluorite | Level 6

Please see the below sample code, 

I am calling macro through Call execute based on a dataset. I want to send 1 email per observation in the dataset. 

eg: If there are 5 obs, I want email to be sent to the email ID present in one of the variables. But it is sending same email twice, so am getting a total of 10 emails, instead of 5.

======================================================

%macro alertMail(a1, a2, a3, a4, a5, a6);
filename alerts1 email to="&emaila." from="abc.abc@123.com"
subject= "DEMO";

data _null_;
file alerts1;
put "Hi,";
put " ";
put "&a1 Approval Rate for &a2. is &a3 , is ";
put " ";
put " &a4 of &a5 from Application Channel &a6 ";
run;

%mend;

 

data Temp1;

set demo nobs=obs;
call execute('%alertMail('||a1||','||a2||','||a3||',' ||a4|| ',' ||a5|| ','||a6||')');
stop;
run;

===================================================

5 REPLIES 5
Reeza
Super User
Why do you have this option in there?
nobs=obs

I think if you remove that it should send for once for each record in the demo set, which is what you're after.
Kurt_Bremser
Super User

The NOBS= doesn't have an effect:

%macro testmac(name);
data _null_;
put "Name=&name.";
run;
%mend;

data _null_;
set sashelp.class nobs=obs;
call execute('%testmac('||name||')');
stop;
run;

Log from SAS On Demand:

 69         %macro testmac(name);
 70         data _null_;
 71         put "Name=&name.";
 72         run;
 73         %mend;
 74         
 75         data _null_;
 76         set sashelp.class nobs=obs;
 77         call execute('%testmac('||name||')');
 78         stop;
 79         run;
 
 NOTE: There were 1 observations read from the data set SASHELP.CLASS.
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       user cpu time       0.01 seconds
       system cpu time     0.00 seconds
       memory              619.68k
       OS Memory           23712.00k
       Timestamp           02.11.2021 09:19:21 vorm.
       Step Count                        24  Switch Count  0
       Page Faults                       0
       Page Reclaims                     94
       Page Swaps                        0
       Voluntary Context Switches        0
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           0
       
 
 NOTE: CALL EXECUTE generated line.
 1         + data _null_; put "Name=Alfred"; run;
 
 Name=Alfred
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              460.84k
       OS Memory           23712.00k
       Timestamp           02.11.2021 09:19:21 vorm.
       Step Count                        25  Switch Count  0
       Page Faults                       0
       Page Reclaims                     42
       Page Swaps                        0
       Voluntary Context Switches        0
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           0
       
 
 80         
SASKiwi
PROC Star

What does your SAS log report? In any case your DATA step should look like this:

data Temp1;
set demo;
call execute('%alertMail('||a1||','||a2||','||a3||',' ||a4|| ',' ||a5|| ','||a6||')');
run;
Quentin
Super User

Hi,

 

Your filename statement sends email to &emaila, but that macro variable is never created in the macro.  I would try making a simple example (without the emailing), just so that you can focus on getting CALL EXECUTE working.  Once that is working like you want, you can add the emailing into the macro.  Below is a simplified example of your code, with the emailing removed.  I usually use %NRSTR() in call execute.  It simplifies macro timing (may or may not be an issue here, depending on what your real code is doing) and also makes the log much easier to read.  You can see in the log every macro invocation generated by CALL EXECUTE.

 

%macro alertMail(a1, a2);
  data _null_;
    put "&a1 &a2";
  run;
%mend;

data demo ;
  input a1 : $5. a2 : $3.;
  cards ;
hi    mom
hello dad
;
run ;

data Temp1;
 set demo ;
 call execute('%nrstr(%%)alertMail('||a1||','||a2||')');
run;

Log is:

NOTE: There were 2 observations read from the data set WORK.DEMO.
NOTE: The data set WORK.TEMP1 has 2 observations and 2 variables.

NOTE: CALL EXECUTE generated line.
1   + %alertMail(hi   ,mom)

hi mom

2   + %alertMail(hello,dad)

hello dad

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1337 views
  • 0 likes
  • 5 in conversation