我试图编写一个宏函数,该宏函数从数据集中获取属性,然后将其存储为宏变量。我想以一种可以用于多个数据集和多个宏变量的方式编写此宏函数。
这是怎么回事:
%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;
每当我尝试运行时,我都会得到如下注释:
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))/";
symputx
是否有禁止传入表示宏变量名称的宏变量的规则?
答案 0 :(得分:0)
确保扩展宏变量时正在生成有效的SAS代码。特别是这样的声明:
call symputx(&storage_var., &var_name., "G");
将要求您使用要创建的宏变量的名称来对宏进行引用。像这样:
%ExtractACell(dataset=sashelp.cars, storage_var="mymvar", rownum=1, var_name=Make);
使用此语句编写宏可能会更简单。
call symputx("&storage_var", &var_name., "G");
然后您可以在宏变量名周围不加引号的情况下调用:
%ExtractACell(dataset=sashelp.cars, storage_var=mymvar, rownum=1, var_name=Make);
PS如果您需要该宏,则整个过程可能会混乱。