0
votes

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?

1
Can you show how you call macro? What values is storage_var equals? I think, You should use call symputx(“&storage_var.”,”&var_name”,”G”)Alexey Sigida
If the value you are storing in the macro variable is a character string longer than 262 characters, you can always use the option NOQUOTELENMAX; to suppress the warnings. You can use a string longer than 262 characters, but SAS warns you as longer strings are sometimes the result of unbalanced quotes.cmjohns

1 Answers

0
votes

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.