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

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. 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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.

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

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.

ChrisNZ
Tourmaline | Level 20

Why would %let type = upcase(Type) be wrong? 

It's not wrong.  The macro variable TYPE simply contains letters and parentheses.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

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
  • 2 replies
  • 1944 views
  • 1 like
  • 3 in conversation