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.
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!
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.
Ready to level-up your skills? Choose your own adventure.