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

Hi,

I got an error message when the following code were submitted. It says "Apparent invocation of macro not resolved.". Does anyone hvae any insight? Thank you.

 

proc sql;

create table a as

select distinct *

from test data

where lower(last_name) like "%&proj%";

quit;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Probably the easiest is to build up the string with the % in it in a way that does not trigger the macro processor.

Here is one way.

%let name=fred;
proc sql noprint;
create table a as
 select distinct *
 from sashelp.class
 where lower(name) like '%'||"&name"||'%'
;
quit;

 

View solution in original post

5 REPLIES 5
Reeza
Super User

SAS is looking for a macro because you have %proj

 

its a warning not an error though? 

 

Can you use the find or index function instead if you need to avoid the warning? 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

It is this code line:

where lower(last_name) like "%&proj%";

If you use macro constructs = % or & witihin double quotes, then then macro preprocessor is invoked.  Now it will resolve &proj. to its value, and then look for a macro called %<proj value>.  

 

Use SAS functions to search for a string - index() for instance.  Or avoid using macro paramters, is there any reason why &proj is used?

lionking19063
Fluorite | Level 6

I used index as you mentioned, it works fine. Just wonder if there is a way to fix the error in the existing SAS codes instead of trying another way. Thanks.

Tom
Super User Tom
Super User

Probably the easiest is to build up the string with the % in it in a way that does not trigger the macro processor.

Here is one way.

%let name=fred;
proc sql noprint;
create table a as
 select distinct *
 from sashelp.class
 where lower(name) like '%'||"&name"||'%'
;
quit;

 

lionking19063
Fluorite | Level 6
The answers works perfectly. Thank you so much for your help.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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