Dear expert
I have the following url:
url=blogs.sas.com/content/sastraining/2011/09/23/sas-authors-tip-macro-functions-eval-and-sysevalf/#:~:text=The %EVAL function
evaluates expressions using integer arithmetic.,in more detail how to construct macro expressions. ;
And I'm trying to store it into a macro var, without getting the %eval function getting interpreted by the compiler
The final outcome I expect to be stored in the macro var is to have the URL stored as text into single quotes ( " ' " + &url + " ' ")
Any hints appreciated
If you want to resolve a macro variable and then mask any macro triggers that results from that resolution, you need %SUPERQ.
Like:
data test;
url='blogs.sas.com/content/sastraining/2011/09/23/sas-authors-tip-macro-functions-eval-and-sysevalf/#:~:text=The %EVAL function
evaluates expressions using integer arithmetic.,in more detail how to construct macro expressions.';
call symputx('url',url) ;
run;
%let urls=%superq(url) ;
%put &=urls ;
%let macrovariable=%str(url=blogs.sas.com/content/sastraining/2011/09/23/sas-authors-tip-macro-functions-eval-and-sysevalf/#:~:text=);
%put ¯ovariable;
You have cut the url address. The full address include the %EVAL keywords, which is generating errors described above
Is this what you want?
%let macrovariable=%nrstr('url=blogs.sas.com/content/sastraining/2011/09/23/sas-authors-tip-macro-functions-eval-and-sysevalf/#:~:text=The %EVAL function
evaluates expressions using integer arithmetic.,in more detail how to construct macro expressions. ;');
%put ¯ovariable;
Yeah, I think we are near a solution. So the URLs are extracted iteratively in a code. A proxy is the following:
data test;
url='blogs.sas.com/content/sastraining/2011/09/23/sas-authors-tip-macro-functions-eval-and-sysevalf/#:~:text=The %EVAL function
evaluates expressions using integer arithmetic.,in more detail how to construct macro expressions.';
run;
proc sql;
select strip(url)into:url
from test;
quit;
%let urls=%nrstr(&url);
%put &urls;
The %nrstr seems stopping the %Eval triggering in the text but does not allow the first macro var to resolve.
If you want to resolve a macro variable and then mask any macro triggers that results from that resolution, you need %SUPERQ.
Like:
data test;
url='blogs.sas.com/content/sastraining/2011/09/23/sas-authors-tip-macro-functions-eval-and-sysevalf/#:~:text=The %EVAL function
evaluates expressions using integer arithmetic.,in more detail how to construct macro expressions.';
call symputx('url',url) ;
run;
%let urls=%superq(url) ;
%put &=urls ;
73 data test;
74 url='blogs.sas.com/content/sastraining/2011/09/23/sas-authors-tip-macro-functions-eval-and-sysevalf/#:~:text=The %EVAL
74 ! function
75 evaluates expressions using integer arithmetic.,in more detail how to construct macro expressions.';
76 call symputx('url',url);
77 run;
NOTE: The data set WORK.TEST has 1 observations and 1 variables.
NOTE: Compressing data set WORK.TEST increased size by 100.00 percent.
Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
SYMBOLGEN: Macro variable URL resolves to
blogs.sas.com/content/sastraining/2011/09/23/sas-authors-tip-macro-functions-eval-and-sysevalf/#:~:text=The %EVAL
function evaluates expressions using integer arithmetic.,in more detail how to construct macro expressions.
ERROR: %EVAL must be followed by an expression enclosed in parentheses.
ERROR: Invalid symbolic variable name
BLOGS.SAS.COM/CONTENT/SASTRAINING/2011/09/23/SAS-AUTHORS-TIP-MACRO-FUNCTIONS-EVAL-AND-SYSEVALF/#:~:TEXT=THE %EVAL FUNCTION
EVALUATES EXPRESSIONS USING INTEGER ARITHMETIC.,IN MORE DETAIL HOW TO CONSTRUCT MACRO EXPRESSIONS..
Still getting the %EVAL error triggered
The log is NOT showing the statement that triggered that note.
Please show the code you used.
Did you call the %SUPERQ() function? Did you make sure to pass it just the NAME of the macro variable you want quoted? Not the VALUE of the macro variable.
Sorry, I checked and the function doesn't need the "&" for the macro recall. Terrific. Amazing function to know!
So now you have introduced data steps and SQL into this process. Why?
Its not clear to me where you are going — you seem to know but I don't understand.
Anyway, I think @Quentin has solved the problem by masking properly.
I don't understand.
The value you showed does not have any %EVAL() function call.
If the goal is to enclose the value in single quotes why not just do that?
%let url='some string in quotes';
Are you saying you want to create part of the string from the value of some macro code? If so then try using %BQUOTE() to allow the macro code to resolve inside the single quotes.
%let word=string;
%let url=%bquote('some &word. in quotes');
There is an %EVAL keyword in the text of the URL. URls are extracted iteratively from a dataset. So proxy code like this, using your suggestion:
data test;
url='blogs.sas.com/content/sastraining/2011/09/23/sas-authors-tip-macro-functions-eval-and-sysevalf/#:~:text=The %EVAL function
evaluates expressions using integer arithmetic.,in more detail how to construct macro expressions.';
run;
proc sql;
select strip(url)into:url
from test;
quit;
%let urls=%bquote('&url');
%put &urls;
Error generated
SYMBOLGEN: Macro variable URL resolves to
blogs.sas.com/content/sastraining/2011/09/23/sas-authors-tip-macro-functions-eval-and-sysevalf/#:~:text=The %EVAL
function evaluates expressions using integer arithmetic.,in more detail how to construct macro expressions.
ERROR: %EVAL must be followed by an expression enclosed in parentheses.
ERROR: %EVAL must be followed by an expression enclosed in parentheses.
83
84
85 %let urls=%bquote('&url');
86
87 %put &urls;
SYMBOLGEN: Macro variable URLS resolves to
'blogs.sas.com/content/sastraining/2011/09/23/sas-authors-tip-macro-functions-eval-and-sysevalf/#:~:text=The %EVAL
function evaluates expressions using integer arithmetic.,in more detail how to construct macro expressions.'
SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing.
ERROR: %EVAL must be followed by an expression enclosed in parentheses.
'blogs.sas.com/content/sastraining/2011/09/23/sas-authors-tip-macro-functions-eval-and-sysevalf/#:~:text=The %EVAL function
evaluates expressions using integer arithmetic.,in more detail how to construct macro expressions.'
If you want the string in single quotes, the easiest thing to do is write the single quotes. They will hide any macro triggers.
%let url='blogs.sas.com/content/sastraining/2011/09/23/sas-authors-tip-macro-functions-eval-and-sysevalf/#:~:text=The %EVAL function
evaluates expressions using integer arithmetic.,in more detail how to construct macro expressions. ' ;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.