简体   繁体   English

带有返回值的SAS宏,之后带有更多文本

[英]SAS Macro with Return value with more text afterwards

Is it possible to return a value from a SAS macro, and continue the current SAS line after returning the value? 是否可以从SAS宏返回值,并在返回值后继续当前的SAS行?

eg Desired output to SAS (without quotes): 例如,期望输出到SAS(不带引号):

"set test.hello_2018_2020_2028;" “设置test.hello_2018_2020_2028;”

I've tried the following: 我尝试了以下方法:

%MACRO returnFunc(passVar);
    %local testReturn;
    %let testReturn = %eval(&passVar +1);
    &testReturn
    %return;
%MEND returnFunc;

%MACRO test;
    %local var1;
    %local varPassed;
    %local anotherVar;

    %let var1 = 2018;
    %let varPassed = 2019;
    %let anotherVar = 2028;

    set test.hello_&var1._%returnFunc(&varPassed)_&anotherVar;
%MEND test;

However I get errors like the following: 但是我得到如下错误:

  • File test.hello_2018_2020.DATA does not exist 文件test.hello_2018_2020.DATA不存在

  • File WORK._2028 Does not exist 文件WORK._2028不存在

So the macro returns the value fine, however it starts trying to make another set statement instead of adding _&anotherVar to the set statement 因此该宏返回的值很好,但是它开始尝试制作另一个set语句,而不是在set语句中添加_&anotherVar

Yes %UNQUOTE and remove the . 是%UNQUOTE并删除。 after the macro call. 在宏调用之后。

111  %MACRO returnFunc(passVar);
112      %local testReturn;
113      %let testReturn = %eval(&passVar +1);
114      &testReturn
115      %return;
116  %MEND returnFunc;
117
118  %MACRO test;
119      %local var1;
120      %local varPassed;
121      %local anotherVar;
122
123      %let var1 = 2018;
124      %let varPassed = 2019;
125      %let anotherVar = 2028;
126
127      set %unquote(test.hello_&var1._%returnFunc(&varPassed)_&anotherVar);
128  %MEND test;
129  options mprint=1;
130  data _null_;
131     %test;
MPRINT(TEST):   set
MPRINT(TEST):   test.hello_2018_2020_2028;
ERROR: Libref TEST is not assigned.
132     run;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM