简体   繁体   中英

SAS - Dynamically adding text to an email via a %macro

I'm attempting to dynamically display text within an email by using a %macro in the place of the dynamic text. This was working, but after adding a few additional lines of text to my email, it stopped working. So, I'm unsure of what is causing the actual issue. Reverting back to where I was when it was working no longer works.

My macro I'm calling:

%macro PrintStuff(arrayOfThings);
    %local i next_element;
    %do i=1 %to %sysfunc(countw(&arrayOfThings));
        %let next_element = %scan(&arrayOfThings, &i);
        %DO;
            %PUT "&next_element info is as follows:";
            %PUT "some text here";
            %PUT "some text there";
            %PUT "text all over!!!";
            %PUT "Do you even text?";
        %END;
    %end;
%mend PrintStuff;

email code:

DATA _null_;
    File mailFile;
    PUT "This is email text. This shows up fine in the email";
    %PrintStuff(&someArray);
    PUT "This closes the email, and this shows up fine in the email when it is received!"
RUN;

I've tried a few different things here. I've tried ONLY having %PrintStuff(&myArrayOrList) in the email. I've tried it with and without a closing ; semicolon. I'm not sure where this went wrong.

The log appears this way after the code has run successfully:

50         DATA _null_;
51          File outmail;
52          PUT "This is email text. This shows up fine in the email";
53         
54          %PrintStuff(&someArray)
"ResolvedElementName info is as follows:"
"some text here"
"some text there"
"some text all over!!!"
"Do you even text?"
55         
56          PUT "This closes the email, and this shows up fine in the email when it is received!";
57         RUN;

It worked, and now it doesn't, and I'm not sure how it could have worked before now. Any advice would be greatly appreciated!!! Thanks in advance!

Put in data step writes into output table/file (ie outmail in your example), %put in your macro writes into log. Try replacing %put in the macro by put - it will add those 5 lines to your data step.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM