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

%macro car_type(ty=);
proc sql;
create table tmp as
select *
from cars
where upcase(type_new) like "%&ty.%"
;quit;
%mend;

 

The part highlighted in red triggers an error. How to get around this? Please help. Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Separate the parts, so no macro resolution is tried:

%macro car_type(ty=);
proc sql;
create table tmp as
select *
from sashelp.cars
where upcase(type) like "%"!!"&ty."!!"%"
;
quit;
%mend;

%car_type(ty=SUV)

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Wrap the % in the %Nrstr Macro Quoting Function

Sameer440909
Calcite | Level 5

Thanks for the replying. I tried but empty data is generated.

Would be very helpful if you can show the exact syntax.

This is how I have written based on your suggestion,

where upcase(type_new) like "%nrstr(% &ty.%)"

Kurt_Bremser
Super User

Separate the parts, so no macro resolution is tried:

%macro car_type(ty=);
proc sql;
create table tmp as
select *
from sashelp.cars
where upcase(type) like "%"!!"&ty."!!"%"
;
quit;
%mend;

%car_type(ty=SUV)
Sameer440909
Calcite | Level 5
Thank you so much @Kurt_Bremser. The solution worked fine. Thanks again
Ksharp
Super User
Using CONTAINS operator instead.

where upcase(type_new) contains "&ty."

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
  • 376 views
  • 3 likes
  • 4 in conversation