英文:
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 > 0` 的观测数量。如果没有观测,它将返回0;否则,返回观测数量。如果观测数量大于0,将发送一封电子邮件。
```sas
%macro send_email;
/* 打开数据集并使用 where 语句计算符合条件的观测数量 */
%let dsid = %sysfunc(open(gridwork.MATCH_TRACKER(where=(Claim_Number > 0)));
%let nobs = %sysfunc(attrn(&dsid, nlobsf));
%let rc = %sysfunc(close(&dsid));
%if &nobs > 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;
英文:
Try changing your data step to this instead. It will count the number of observations in gridwork.MATCH_TRACKER
where the claim_number > 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 > 0))));
%let nobs = %sysfunc(attrn(&dsid, nlobsf));
%let rc = %sysfunc(close(&dsid));
%if &nobs > 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;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论