%let type=Gold;
title "&type Customers";
proc sql number;
select Name, Age_Group, Type
from mc1.customers
where Type contains "&type";
quit;
title;
%macro customers(type);
title "&type Customers";
proc sql number;
select Name, Age_Group, Type
from mc1.customers
where type="%upcase(&type)";
quit;
title;
%mend customers;
%customers(Gold)
In the first program you are generating this WHERE clause:
where Type contains "Gold"
In the second one you generate this WHERE clause instead:
where type = "GOLD"
So you should see different results. The only value that satisfies the second test is GOLD which does not contain any lowercase letters and so could not contatin Gold.
In the first program you are generating this WHERE clause:
where Type contains "Gold"
In the second one you generate this WHERE clause instead:
where type = "GOLD"
So you should see different results. The only value that satisfies the second test is GOLD which does not contain any lowercase letters and so could not contatin Gold.
It's most likely uppercase is used in the macro definition (where type="%upcase(&type)").
Check your data, look at your first sql step that works with %let statement.
Try this:
%macro customers(type);
title "&type Customers";
proc sql number;
select Name, Age_Group, Type
from mc1.customers
where type="&type";
quit;
title;
%mend customers;
%customers(Gold);
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.