I am writing a macro to send e-mails, using a rest api available in our company.
(The macro will be deployed as a sasautos
macro.) The attachments parameter should allow to pass a list of file paths, so this should be valid code;
%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"
);
Within the macro %send_mail()
, I would like to put the attachments parameter in a string attachment_list
Perl Regular Expressions in SAS.
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;
(I hope I did not make errors while simplifying the code for you.)
However, the quotes within the parameter mess up with the quotes in attachment_list = "&attachments";
Does anyone see a work around, so that my users should not worry about this?
The following are not acceptable solutions:
- Ask my users to double their quotes, as in
, attachments = ""/our/data/répertoire français/file1.xlsx"" ""/our/data/some_folder/file with blanks.xlsx""
. (They would not understand and I would get one of them on the phone weekly.) - Ask them to use
'
instead of"
, because then they cannot use macro variables within their call to my macro