0
votes

I have a a table called Tabling.

Name                  Number
Price A               10
Price B               11
Quantity A            12
Quantity B            13

How do I write a Proc SQL piece of Code where I create a variable Saying %let Variable = "Price" and then say something like this

I am creating a table called selection from Tabling

Proc SQL;
Create Table Selection As
Select * 
From Tabling
Where Name Contains %Variable;
Quit;

What I need is for the Proc SQL to relate back to the macro variable without explicitly stating "Price" in the SQL Code.

Please help me with this. Thank you in advance.

1
Please, use CTRL+K to format text code.stat

1 Answers

0
votes

You are looking for a macro variable, created by your code:

%let variable = Price;

Please, delete those " ", or they will be a part of your macro variable (variable should contain Price, not "Price", this is not a datastep code, this is macro language).

Your macro variable will be claimed using ampersand, not percent. Hence, you won't have Where Name contains %variable; but where Name contains "&variable";.

Also consider to upcase each string, string comparison is case sensitive, "Price" is different from "price", hence you can use where upcase(name) contains upcase("&variable"); .

You seriously need to go through a book or a guide to macro language programming to understand what you are doing. Let me know if you will need any further clarifications.