我正在编写一个宏来发送电子邮件,使用我们公司提供的 REST API。 (该宏将部署为
sasautos
宏。) Attachments 参数应允许传递文件路径列表,因此这应该是有效的代码;
%send_mail(subject=Voorbeeld e-mail
, [email protected]
, message_html =Dear collegue<br/><br/>Here are the promised files.<br/><br/>Regards<br/>Dirk Horsten
, attachments = "/our/data/répertoire français/file&today_yymmdd..xlsx"
"/our/data/some_folder/file with blanks.xlsx"
);
在宏
%send_mail()
中,我想将附件参数放入字符串中attachment_list
SAS中的Perl正则表达式。
data _null_;
...
length fileRef $8 xpath $256 ;
attachment_list = "&attachments";
_rxAttachment = prxParse('/".+?"/');
_rxStart = 1;
_rxStop = length(attachment_list);
call prxNext(_rxAttachment, _rxStart, _rxStop, attachment_list, _rxPos, _rxLen);
if not _rxPos then putlog 'WARNING: unable to parse your attachments';
else do;
attach_nr = 0;
do while (_rxPos);
attach_nr = attach_nr + 1;
xpath = substr(attachment_list, _rxPos, _rxLen);
fileRef = cats('_ML_',attach_nr);
call execute (catx(' '
, 'filename'
, fileRef
, xpath
, ';'));
length attachRef_N attachName_N attachType_N $32;
attachRef_N = cats('attachRef_', attach_nr);
call symputx(attachRef_N, fileRef, 'local');
attachName_N = cats('attachName_', attach_nr);
call symputx(attachName_N, scan(xpath, -1, '/'), 'local');
end;
call symputx('attach_count', attach_nr, 'local');
end;
...
run;
(希望我在为您简化代码时没有犯错误。)
但是,参数中的引号与
attachment_list = "&attachments";
中的引号混淆了,有人看到解决方法吗,这样我的用户就不用担心这个问题了?
以下是不可接受的解决方案:
, attachments = ""/our/data/répertoire français/file1.xlsx"" ""/our/data/some_folder/file with blanks.xlsx""
所示。 (他们不会理解,我每周都会给其中一个人打电话。)'
而不是 "
,因为这样他们就无法在调用我的宏时使用宏变量也许您可以将带引号的字符串加载到数组中,然后可以引用它们或根据需要进行其他处理。
50 %let attachments = "/our/data/répertoire français""/file/today_yymmdd..xlsx"
51 "/our/data/some_folder/file with blanks.xlsx";
52 %let attw = %sysfunc(countw(%superq(ATTACHMENTS),%str( ),Q));
53 %put NOTE: &=attw;
NOTE: ATTW=2
54 data _null_;
55 array _att[&attw] $256 (&attachments);
56 put _all_;
57 do i = 1 to dim(_att);
58 _att[i] = quote(_att[i],"'");
59 end;
60 put _all_;
61 run;
_att1=/our/data/répertoire français"/file/today_yymmdd..xlsx _att2=/our/data/some_folder/file with blanks.xlsx i=. _ERROR_=0 _N_=1
_att1='/our/data/répertoire français"/file/today_yymmdd..xlsx _att2='/our/data/some_folder/file with blanks.xlsx i=3 _ERROR_=0 _N_=1