BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ltsmash89
Calcite | Level 5

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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;

 

 

View solution in original post

2 REPLIES 2
Astounding
PROC Star

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;

 

 

Ltsmash89
Calcite | Level 5
Hi Super User. It worked. Made some edits by dropping the ""'s and implemented your code and it worked. Thanks so much

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 2111 views
  • 0 likes
  • 2 in conversation