发送一封电子邮件从SAS,如果在项目完全运行后最终表中有数据。

huangapple go评论52阅读模式
英文:

Sending an Email from SAS with Program if there is data in final table after a project is fully run

问题

以下是您要翻译的内容:

"I have not been able to get an email sent when my program is done running. I would like to send an email if there is a claim number that populates in the Match_Tracker table (this is the final output in the project). Claim_Number is the variable in the Match_Tracker table that I thought would work best. However, It would be better if the criteria was if any data populates in the table itself.


data _null_;
set gridwork.MATCH_TRACKER;
if Claim_Number > 0 then do;
call symput('send_email',1);
stop;
end;
run;

%macro send_email;
%if &send_email > 0 %then %do;
filename outbox email 'gavin.xxx@xx.com';
data _null_;
file outbox to=("gavin.xxx@xx.com") subject = "Test";
put "There is a claim"
put " ";
run;
%end;
%mend;
%send_email;```"

<details>
<summary>英文:</summary>

I have not been able to get an email sent when my program is done running. I would like to send an email if 
there is a claim number that populates in the Match_Tracker table (this is the final output in the project). Claim_Number is the variable in the Match_Tracker table that I thought would work best. However, It would be better if the criteria was if any data populates in the table itself.

%let send_email = 0;

data null;
set gridwork.MATCH_TRACKER;
if Claim_Number > 0 then do;
call symput('send_email',1);
stop;
end;
run;

%macro send_email;
%if &send_email > 0 %then %do;
filename outbox email 'gavin.xxx@xx.com';
data null;
file outbox to=("gavin.xxx@xx.com") subject = "Test";
put "There is a claim";
put " ";
run;
%end;
%mend;
%send_email;




</details>


# 答案1
**得分**: 0

尝试将您的数据步骤更改为以下方式。它将计算 `gridwork.MATCH_TRACKER` 中 `claim_number &gt; 0` 的观测数量。如果没有观测,它将返回0;否则,返回观测数量。如果观测数量大于0,将发送一封电子邮件。

```sas
%macro send_email;

    /* 打开数据集并使用 where 语句计算符合条件的观测数量 */
    %let dsid = %sysfunc(open(gridwork.MATCH_TRACKER(where=(Claim_Number &gt; 0)));
    %let nobs = %sysfunc(attrn(&amp;dsid, nlobsf));
    %let rc   = %sysfunc(close(&amp;dsid));

    %if &amp;nobs &gt; 0 %then %do;
        filename outbox email &#39;gavin.xxx@xx.com&#39;

        data _null_;
            file outbox to=(&quot;gavin.xxx@xx.com&quot;) subject = &quot;Test&quot;;
            put &quot;There is a claim&quot;;
            put &quot; &quot;;
        run;
    %end;
%mend;
%send_email;
英文:

Try changing your data step to this instead. It will count the number of observations in gridwork.MATCH_TRACKER where the claim_number &gt; 0. It will return 0 if there are none, and the number of observations otherwise. If it's > 0, an email will be sent out.

%macro send_email;

    /* Open the dataset and count the number of observations with the where statement */
    %let dsid = %sysfunc(open(gridwork.MATCH_TRACKER(where=(Claim_Number &gt; 0))));
    %let nobs = %sysfunc(attrn(&amp;dsid, nlobsf));
    %let rc   = %sysfunc(close(&amp;dsid));

    %if &amp;nobs &gt; 0 %then %do;
        filename outbox email &#39;gavin.xxx@xx.com&#39;;

        data _null_;
            file outbox to=(&quot;gavin.xxx@xx.com&quot;) subject = &quot;Test&quot;;
            put &quot;There is a claim&quot;;
            put &quot; &quot;;
        run;
    %end;
%mend;
%send_email;

huangapple
  • 本文由 发表于 2023年4月7日 03:53:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/75953283.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定