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.

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