SAS IML传递对宏中定义的变量的引用 [英] SAS IML pass reference to variable defined in macro
问题描述
在SAS/IML中,我尝试将对宏中定义的变量的引用传递给用户定义的模块.模块更改变量值. 由于该函数的调用在do循环中,因此我不能使用& -sign .但是, symget 的使用不起作用.这是我的代码.
In SAS/IML I try to pass to a user defined module a reference to a variable that is defined in macro. The module changes the variable value. Since call of the function is in the do-loop I cannot use &-sign. However use of symget does not work. Here is my code.
proc iml;
start funcReference(argOut);
print "funcReference " argOut;
argOut = 5;
finish funcReference;
store module=funcReference;
quit;
proc IML;
mydata1 = {1 2 3};
call symput ('macVar', 'mydata1');
load module=funcReference;
run funcReference(symget('macVar'));
print mydata1;
quit;
输出显示变量 mydata1 尚未更改:
The output shows that variable mydata1 have not changed:
argOut
funcReference mydata1
mydata1
1 2 3
有什么想法吗?
已解决
非常感谢!
推荐答案
您正在发送临时标量矩阵(SYMGET调用的结果).如文章哦,那些讨厌的临时变量!"
You are sending in a temporary scalar matrix (the result of the SYMGET call). That temporary variable is being updated and promptly vanishes, as explained in the article "Oh, those pesky temporary variables!"
应该使用VALUE和VALSET函数代替宏变量(即文本字符串),如文章您需要发送一个实矩阵以正确更新值,如下所示:
Instead of macro variables (which are text strings), you should use the VALUE and VALSET functions, as described in the article "Indirect assignment: How to create and use matrices named x1, x2,..., xn" You need to send in a real matrix in order for the values to be updated correctly, as follows:
proc IML;
load module=funcReference;
mydata1 = {1 2 3};
call symput('macVar', 'mydata1');
matrixName = symget('macVar'); /* matrix named &mydata1 */
z = value(matrixName); /* z contains data */
run funcReference(z); /* update values in z */
call valset(matrixName, z); /* update data in &mydata1 */
print mydata1;
这篇关于SAS IML传递对宏中定义的变量的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!