Search code examples
sassas-macro

symputx won't let me store different macro variables with the same macro function


I'm trying to write a macro function that gets attributes from a data set, and then stores them as a macro variable. I want to write this macro function in such a way that it can be used for multiple data sets, and multiple macro variables.

What's wrong with this:

%macro ExtractACell(dataset, storage_var, rownum=1, var_name=Make);
data _null_;
    set &dataset. (obs=&rownum. firstobs=&rownum. keep = &var_name.);   
    call symputx(&storage_var., &var_name., "G");
    stop;
run;
%mend ExtractACell;

Whenever I try to run that I get notes like this:

 NOTE: The quoted string currently being processed has become more than 262 bytes long.  You might have unbalanced quotation marks.
 NOTE: The quoted string currently being processed has become more than 262 bytes long.  You might have unbalanced quotation marks.
 27         %let SASWORKLOCATION="%sysfunc(getoption(work))/";

Does symputx have rules against passing in macro variables that represent names of macro variables?


Solution

  • Make sure you are generating valid SAS code when your macro variables are expanded. In particular this statement:

    call symputx(&storage_var., &var_name., "G");
    

    Would require you to call the macro with quotes around the name of the macro variable you want it to create. Like this:

    %ExtractACell(dataset=sashelp.cars, storage_var="mymvar", rownum=1, var_name=Make);
    

    It might be simpler to code the macro using this statement.

    call symputx("&storage_var", &var_name., "G");
    

    Then you could call without the quotes around the macro variable name:

    %ExtractACell(dataset=sashelp.cars, storage_var=mymvar, rownum=1, var_name=Make);
    

    PS Your whole process is probably messed up if you need that macro.