Alex Alex - 1 month ago 14
MySQL Question

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;

Answer

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)