I have the following code, where I from SAS send an automatic mail. The problem is that the macro variable does not get resolved, and I believe it has to do with the quotes but I can't figure out how to solve it.
%let country. = USA;
FILENAME Mailbox
EMAIL TO=("MyMail@gmail.com")
SUBJECT="An Example Mail"
replyto="Mail2@gmail.com"
;
DATA _NULL_;
FILE Mailbox
type='text/html';
PUT "Some Random Text" '<br><br>'
'<a href="MyDirectoryPath\&country.">MyDirectoryPath\&country.</a>' '<br><br>'
;
RUN;
So the line of code that is the problem is:
'<a href="MyDirectoryPath\&country.">MyDirectoryPath\&country.</a>' '<br><br>'
In the mail the following shows up:
MyDirectoryPath\&country
But it should be: MyDirectoryPath\USA, i.e. the macro variable should resolve.
Any suggestions?
Switching " and ' should solve the problem.
Hi @SasStatistics.,
The %let statement has a "." after "country", so I removed it.
The following code:
%let country = USA;
data _null_;
text = cat("Some Random Text"
,'<br><br>'
,'<a href='
,quote("MyDirectoryPath\&country.")
,">MyDirectoryPath\&country.</a>' '<br><br>'"
);
put text;
run;
produces:
Some Random Text<br><br><a href="MyDirectoryPath\USA">MyDirectoryPath\USA</a>' '<br><br>'
Is that what you're looking for?
Kind regards,
Amir.
Build the string using single quotes to mask double quotes, and double quotes around macro variables:
%let country = USA;
data _null_;
string =
'Some Random Text<br><br><a href="' !!
"MyDirectoryPath\&country." !!
'">' !!
"MyDirectoryPath\&country.</a><br><br>"
;
put string;
run;
Switching " and ' should solve the problem.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.