Alex F
Alex F

Reputation: 2274

How to pass a table as a parameter value in SAS for proc sql?

I'm rerunning a twenty line portion of code for multiple data sets where the only line that changes is the table name. Is there a way to parameterize the table name to pass into the code? I've found examples of passing a column as parameter but not an entire table.

Here's an example of what I'm doing where I would want to parameterize TABLE_NAME.

PROC SQL;
SELECT COUNT(number) AS band_1
FROM TABLE_NAME
WHERE VAR < 620

outer union

SELECT COUNT(number) AS band_2
FROM TABLE_NAME
WHERE VAR BETWEEN 620 AND 639;
RUN;

Upvotes: 1

Views: 360

Answers (2)

Robert Soszyński
Robert Soszyński

Reputation: 1188

You can build a macro and provide a parameter, which will be a table name.

%macro union(table_name);
PROC SQL;
    SELECT COUNT(number) AS band_1
    FROM &TABLE_NAME
    WHERE VAR < 620

    outer union

    SELECT COUNT(number) AS band_2
    FROM &TABLE_NAME
    WHERE VAR BETWEEN 620 AND 639;
QUIT;
%mend union;

%union(a)
%union(b)
%union(c)

Upvotes: 1

karan yadav
karan yadav

Reputation: 59

you can use dynamic query like exec ('select * from'+@tablename)

Upvotes: 0

Related Questions