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

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

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 ;
The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.

View solution in original post

12 REPLIES 12
PaigeMiller
Diamond | Level 26
%let macrovariable=%str(url=blogs.sas.com/content/sastraining/2011/09/23/sas-authors-tip-macro-functions-eval-and-sysevalf/#:~:text=);

%put &macrovariable;
--
Paige Miller
dcortell
Pyrite | Level 9

You have cut the url address. The full address include the %EVAL keywords, which is generating errors described above

PaigeMiller
Diamond | Level 26

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 &macrovariable;
--
Paige Miller
dcortell
Pyrite | Level 9

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. 

Quentin
Super User

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 ;
The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
dcortell
Pyrite | Level 9


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

Tom
Super User Tom
Super User

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.

dcortell
Pyrite | Level 9

Sorry, I checked and the function doesn't need the "&" for the macro recall. Terrific. Amazing function to know!

PaigeMiller
Diamond | Level 26

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.

 

 

--
Paige Miller
Tom
Super User Tom
Super User

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');
dcortell
Pyrite | Level 9

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.'

 

 

Quentin
Super User

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. ' ;
The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.

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
  • 12 replies
  • 3123 views
  • 4 likes
  • 4 in conversation