DATA Step, Macro, Functions and more

Need help to include macro variable values in email in SAS

Accepted Solution Solved
Reply
Highlighted
Contributor
Posts: 20
Accepted Solution

Need help to include macro variable values in email in SAS

Hi,

 

My exact task is, I have to show few data values which needs to take values from SAS tables using SAS macro variables and should show in email body. And below is the email smaple body.

 

Mail body required;

Report for April 2017, the total sales amount is 90,500.50.

 

In these, Electronics amount is 20,500 and other business area amountsare (50,300.50), and (20,000.10).

 

Caustion:

 

All above information is strictly confidentail and not sharable.

 

 

To do this, I just started below code and then trying to execute below code but macro variables are not resolved in email using X command. Please suggets me how can we achieve above task

 

data _null_;

x=today();

y=put(x,date9.);

put y;

call symput('getdate',y);

run;

 

%put &getdate;

 

%sysexec export rundate=&getdate;

%sysexec echo $rundate;

 

x 'echo "Run monthly job only on &getdate." | mailx -s "Mail Notification" banu.kumar@xxxxx.com;

 


Accepted Solutions
Solution
Friday
Valued Guide
Posts: 613

Re: Need help to include macro variable values in email in SAS

Are you sure that &GETDATE never resolves - not even in the %PUT?

 

In the X statement you have a mismatched single quote.  Also you cannot surround a macro reference with a single quote and still get resolution.  There are several ways to get around this, try this general form of the X statement:

x %tslit(echo "&getdate");

View solution in original post


All Replies
Solution
Friday
Valued Guide
Posts: 613

Re: Need help to include macro variable values in email in SAS

Are you sure that &GETDATE never resolves - not even in the %PUT?

 

In the X statement you have a mismatched single quote.  Also you cannot surround a macro reference with a single quote and still get resolution.  There are several ways to get around this, try this general form of the X statement:

x %tslit(echo "&getdate");
Contributor
Posts: 20

Re: Need help to include macro variable values in email in SAS

It's working fine. Thanks

Esteemed Advisor
Posts: 5,627

Re: Need help to include macro variable values in email in SAS

%sysexec export rundate=&getdate;
%sysexec echo $rundate;

Both of these commands start a shell; since the change in the environment (new environment variable rundate) is lost when the first shell terminates, the second command won't find $rundate.

Only certain UNIX commands (cd, pwd, setenv, umask) are executed so that they have effect in the context of the SAS session itself.

Contributor
Posts: 20

Re: Need help to include macro variable values in email in SAS

Thanks for your sugegstion. It's helpful for me.

Contributor
Posts: 20

Re: Need help to include macro variable values in email in SAS

Is there any option to bold values in echo command in SAS X statement.

 

x %tslit(echo "Total sales amount is: $500,200.10");

 

OUTPUT require as: Total sales amount is: $500,200.10

 

Please suggest me.

 

 

 

Esteemed Advisor
Posts: 5,627

Re: Need help to include macro variable values in email in SAS


Banu wrote:

Is there any option to bold values in echo command in SAS X statement.

 

x %tslit(echo "Total sales amount is: $500,200.10");

 

OUTPUT require as: Total sales amount is: $500,200.10

 

Please suggest me.

 

 

 


No. echo is a UNIX commandline command that can only handle pure text, without any formatting. Also keep in mind that a data step used to create a mail message (using filename email) can only handle text.

But you can use that data step to write HTML code into the mail, which allows you to use HTML formatting tags. An example for this can be found in http://support.sas.com/resources/papers/proceedings10/060-2010.pdf

Contributor
Posts: 20

Re: Need help to include macro variable values in email in SAS

I have tried same as you mentioned, but getting "ERROR: Email: The connection was refused."

I have given options like emailhost and emailsys. Any suggestions on this?

 

Esteemed Advisor
Posts: 5,627

Re: Need help to include macro variable values in email in SAS

So your first task should be to make a very simple, "hello world" type mail work with filename email.

"Connection refused" might indicate that

- there is no SMTP server active on the host you named

- it requires credentials

- it only accepts connections from certain clients

Check with your mail administrator how to access the SMTP server.

Post a Question
Discussion Stats
  • 8 replies
  • 68 views
  • 0 likes
  • 3 in conversation