BookmarkSubscribeRSS Feed
JJP1
Pyrite | Level 9

hi, i am running the below user written code in SAS DI job and i am getting error please suggest

 

%let Email_Address=;
proc sql noprint;
select distinct cat('"',strip(Email_Address),'"')
into :Email_Address
separated by ' '
from yyyyy
;
quit;
%if %eval(&syscc > 0) %then %return;
%put Email_Address = &Email_Address;
%macro send_email;
%if &Email_Address ne %then %do;
filename email email
from=('xxxxxxx.com')
sender=('xxxxxxx.com')
to=(&Email_Address)
cc=('rrrrrrr.com' 'xxxxxxx.com' 'CCCCCC.com')
subject=('cccccccccccccccccccccccc')
importance='high'
type='text/html'
CT ='text/html'
;
title;
ods html body=email;
ods html text='Hello';
ods html text=' ';
ods html text='gggggggggggggggggggggggggggggggggggg';
ods html text=' ';
ods html text='uyuuuuuuuuuuuuuuuuuuuu.';
ods html text=' ';
ods html text='ccccccccccccccccccccccccccccc xxxxxxx.com .';
ods html text=' ';
ods html text='iiiiiiiiiiiiiiiiiiiiiiiiiiiiiit';
ods html text=' ';
proc print data=output1 label noobs;quit;
%if %eval(&syscc > 0) %then %return;
ods html text=' ';
ods html text='Thanks';
ods html text='XXXXXXXXXXXXXXX';
ods html text='Email: xxxxxxx.com';
ods _all_ close;
%end;
%mend;
%send_email;



JJP1_0-1600670267153.png

 

 

6 REPLIES 6
Kurt_Bremser
Super User

Since SAS 9.4M5, you can use %IF-%THEN-%DO-%END in open code, but not %IF-%THEN without the %DO-%END.

Expand this

%if %eval(&syscc > 0) %then %return;

to this

%if %eval(&syscc > 0) %then %do; %return; %end;
JJP1
Pyrite | Level 9

Thanks @Kurt_Bremser .

but iam still getting error after expanding the code as you suggested. would you pleas correct me

JJP1_0-1600680443269.png

 

andreas_lds
Jade | Level 19

Please verify that you are using at least 9.4m5.

JJP1
Pyrite | Level 9

I am using SAS DI 4.4 application please

Astounding
PROC Star

Just a few notes about things you willl need to clean up sooner or later ...

 

First, don't define %SEND_EMAIL inside an %IF %THEN condition.  Pull out the definition of the macro so it stands alone.  The other logic can still call %SEND_EMAIL.  That will make your logic easier to understand and debug.

 

Second, what is the first %RETURN statement supposed to do?  Even if you solve for %IF in open code, there is no way to make a %RETURN statement valid outside of a macro definition.

 

Finally, beware of this comparison: 

%if &Email_Address ne %then %do;

Some email addresses contain a dash.  If that occurs, macro language will interpret that as subtraction and give you an error message.  Safer:

%if %length(&Email_Address) %then %do;

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 3094 views
  • 1 like
  • 4 in conversation