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

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? 

1 ACCEPTED SOLUTION

Accepted Solutions
5 REPLIES 5
Amir
PROC Star

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.

SasStatistics
Pyrite | Level 9
The solution was: "Switching " and ' should solve the problem."
Kurt_Bremser
Super User

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;
andreas_lds
Jade | Level 19

Switching " and ' should solve the problem.

SasStatistics
Pyrite | Level 9
Do you know why this is so? Is it some general principle?

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
  • 854 views
  • 2 likes
  • 4 in conversation