0

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.

Jakob Egger
  • 11,981
  • 4
  • 38
  • 48
cordelia
  • 133
  • 3
  • 12

1 Answers1

0

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.

stat
  • 699
  • 3
  • 10
  • Thanks a lot for your help. Will follow your tips with regard to the formatting and macro language programming. – cordelia Aug 01 '15 at 03:19