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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 601 views
  • 2 likes
  • 4 in conversation