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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.