I want to make a Macro case in-sensitive so that if the user for instance writes Type or TYpE in the positional argument (see code below) it does not matter. My code is:
%macro Customers(Type);
%let Type = %sysfunc(upcase(&Type)); *why is Type = upcase(Type) wrong? I.e. why do I have to create a macro variable?;
title "&type Customers";
proc sql number;
select Name, Age_Group, Type
from mc1.customers
where upcase(Type) contains "&Type";
quit;
title;
%mend Customers;
Why would Type = upcase(Type) be wrong?
So the question is, why do I have to create a macro variable for the positional argument in this case?
Thanks.
Hello @SasStatistics,
Macro parameters are local macro variables. You cannot use the DATA step syntax varname=value of an assignment statement for macro variables. The %LET statement in your macro does not create a new macro variable, it changes the value of the existing macro variable Type.
But you can simplify the correct %LET statement by using the %UPCASE macro function:
%let Type = %upcase(&Type);
I would be a bit concerned about your WHERE condition using the CONTAINS operator because, for example, it would also select INACTIVE customers when you actually want ACTIVE customers.
Hello @SasStatistics,
Macro parameters are local macro variables. You cannot use the DATA step syntax varname=value of an assignment statement for macro variables. The %LET statement in your macro does not create a new macro variable, it changes the value of the existing macro variable Type.
But you can simplify the correct %LET statement by using the %UPCASE macro function:
%let Type = %upcase(&Type);
I would be a bit concerned about your WHERE condition using the CONTAINS operator because, for example, it would also select INACTIVE customers when you actually want ACTIVE customers.
> Why would %let type = upcase(Type) be wrong?
It's not wrong. The macro variable TYPE simply contains letters and parentheses.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.