本文介绍了使用宏变量名称调用宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在SAS中,是否可以使用值是宏名称的宏变量来调用对宏的调用?类似于以下内容:
Is it possible in SAS to invoke a call to a macro using a macro variable whose value is the macro's name? Something like the following:
%MACRO TEST (macroName, var1, var2, var3, var4, var5);
%put LOG: %¯oName(&var1);
%MEND;
%TEST(testName,testVar1);
对理查德的回答.我尝试遵循您的解决方案,但仍使用以下代码获得未解析宏YearMonthString的表观调用":
In response to Richard's answer. I tried following your solution, but am still getting an "apparent invocation of macro YearMonthString not resolved" using the following code:
%MACRO YearMonthString(nYear,nMonth);
/* Builds a string in the format YYYYMM using passed nYear and nMonth */
%local returnVal;
/*Build the string */
%let returnVal = &nYear.%AddLeadingZerosToMakeNumXLength(2,&nMonth);
/*Write to LOG */
%put MACRO LOG: YearMonthString(nYear= &nYear, nMonth= &nMonth) will return &returnVal;
/* return returnVal */
&returnVal
%MEND;
%MACRO TEST (macroName, var1, var2, var3, var4, var5);
%local loopCount;
%let loopCount = 1;
%do i=1 %to 13;
%¯oName.(&var1,&loopCount);
%let loopCount = %eval(&loopCount+1);
%end;
%MEND;
%TEST(YearMonthString,2018,8,,,);
推荐答案
可以!构造为%
&
宏符号.这是一个演示:
Yes you can! The construct is %
&
macro-symbol. Here is a demonstration:
%macro one();
%put &SYSMACRONAME;
%mend;
%macro two();
%put &SYSMACRONAME;
%mend;
%macro dispatch (routine);
%&routine.()
%mend;
%dispatch (one)
%dispatch (two)
---- LOG ----
13 %dispatch (one)
ONE
14 %dispatch (two)
TWO
这篇关于使用宏变量名称调用宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!