Hi All,
I'm very new to SAS Base so forgive if this question seems basic. I've created a Macro that emails a PowerPoint file to a list of emails. The list will contain at most 8 email addresses and are inputted into the Macro via Macro variables and will be of the form email_1="John.Smith@abc.ie", (note the "" are required). If only a few emails are required then the email arguments are left blank, i.e. email_2 =
A colleague mentioned that a security measure should be put on the list of emails such that if the email address is external, i.e. not "@abc.ie" or (blank) then the Macro should not run or the PowerPoint should not be emailed to these emails. What I tried to do was the following within the Macro:
/*Note this is repeated 8 times for each macro email variable input*/
%if substr(&email_1.,length(&email_1.)-5,6) not in ('abc.ie', '') %then %do;
%let email_1 = '';
%put &email_1;
%end;
I.e. if the email is not blank or is not an abc.ie. email then replace the email variable with a blank.
However when I run the above I get the following error:
ERROR: Required operator not found in expression: substr(&email_1.,length(&email_1.)-5,6) %not %in ('abc.ie', '')
Any ideas on what the problem could be? I've tried a number of variations and done some Googling but have had no luck. If this is the wrong place to post then please let me know. Also not the internal email address will always end in '@abc.ie'.
If you need some data, let me know and I an create some dummy data.
Kind Regards,
Lorcan
You're starting in a touch place, both sending emails and using macro language to do it. Some of the principles of macro language that you are encountering ... macro language does not process data and does not (without special handling) execute DATA step functions. It can execute macro language functions, which is all you need for this particular purpose (so we don't need to talk about what "special handling" means). And second, macro language assumes that strings are strings, and so does not require quotes. To apply this to your program, this would be an appropriate revision:
%if %substr(&email_1.,%length(&email_1.)-5,6) ne abc.ie %then %do;
There are a variety of ways to check whether a macro variable contains a null value, and it wasn't clear to me if you wanted to check for a null value or for two quotes. So I removed that piece. You can add it back in, but do not use the IN operator in macro language. That also requires special handling. So a possibility would be:
%if %substr(&email_1.,%length(&email_1.)-5,6) ne abc.ie and %length(&email_1.) > 0 %then %do;
You're starting in a touch place, both sending emails and using macro language to do it. Some of the principles of macro language that you are encountering ... macro language does not process data and does not (without special handling) execute DATA step functions. It can execute macro language functions, which is all you need for this particular purpose (so we don't need to talk about what "special handling" means). And second, macro language assumes that strings are strings, and so does not require quotes. To apply this to your program, this would be an appropriate revision:
%if %substr(&email_1.,%length(&email_1.)-5,6) ne abc.ie %then %do;
There are a variety of ways to check whether a macro variable contains a null value, and it wasn't clear to me if you wanted to check for a null value or for two quotes. So I removed that piece. You can add it back in, but do not use the IN operator in macro language. That also requires special handling. So a possibility would be:
%if %substr(&email_1.,%length(&email_1.)-5,6) ne abc.ie and %length(&email_1.) > 0 %then %do;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.