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

Hello,

 

I am trying to build an email address macro variable for use with the 'emailid' system option for sending email from a SAS program, using the user's network ID (as returned by the automatic macro variable _clientuserid). The program in question may be run by various users and I don't want anyone to have to hard code their email address in the program.

 

I've modified the macro variable code every way I can think of, but except for building it with two macro vars, I always end up with the variable not resolving correctly in the options statement. Is it possible to do it in one %let statement? I feel there must be one simple thing I'm overlooking.

 

Here is my code that works using two %let statements:

 

%let my_login = %sysfunc(compress(&_clientuserid.'@smud.org',"'"));
%let sender = "&my_login";

options emailsys=smtp emailhost=<oursystem> emailport = <ourport> emailed=&sender.;

filename mymail email to=<recipients> subject="SAS test email";
data _null_;
file mymail;
put "This is a test";
run;

 

I am running SAS EG 5.1, processing on a UNIX server.

 

Tamara

 

~Tamara
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Not sure this is better than your current solution. 

I would use dequote + quote functions.

 

You could probably nest your functions as well, using another %sysfunc and the quote function. 

 

%let _clientuserid='awesome';
%let my_login = %sysfunc(quote(%sysfunc(dequote(&_clientuserid))@smud.org));
%put &my_login;

View solution in original post

5 REPLIES 5
Reeza
Super User

Unless I'm missing something, isn't it:

 

 

%let _clientuserid=awesome;
%let my_login = "&_clientuserid.@smud.org";
%put &my_login;
TBarker
Quartz | Level 8

Reeza,

 

Thank you for responding.

 

The system macro variable _clientuserid produces the userid enclosed in single quotes (e.g. 'tbarker'). To mimic this in your code, you would need to put single quotes around the word 'awesome'. Your second let statement would then produce "'awesome'@smud.org", retaining the single quotes around 'awesome'. That causes an error when used in the emailid option.

 

I, too, thought it should be as easy as %let my_login = "&_clientuserid.@smud.org";, but it's the embedded single quotes in the _clientuserid return value that cause the problem, requiring the compress function to get rid of them. And when I try to enclose the my_login value (as I coded it) in double quotes using a variety of methods, SAS produces various errors. Thus the second let statement to enclose the value from the first let statement in double quotes.

~Tamara
Reeza
Super User

Not sure this is better than your current solution. 

I would use dequote + quote functions.

 

You could probably nest your functions as well, using another %sysfunc and the quote function. 

 

%let _clientuserid='awesome';
%let my_login = %sysfunc(quote(%sysfunc(dequote(&_clientuserid))@smud.org));
%put &my_login;
Reeza
Super User

And another option, move the quotes to the options statement and have no quotes in your macro variable.

 

 

TBarker
Quartz | Level 8

Quote/Dequote worked! Now it's just one let statement instead of two. Not a critical requirement, but I like to have as efficient code as possible. I'm sure I had tried the dequote function before, but I was messing with the code so much that I never got it to work in whichever iteration I tried it. And I for some reason had not tried the quote function. Sometimes you just need someone else to come at your problem with a clearer mind. Thank you for your help!

 

~Tamara

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
  • 5 replies
  • 1452 views
  • 0 likes
  • 2 in conversation