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.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.