0

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;

The output shows that variable mydata1 have not changed:

argOut 
funcReference mydata1 

mydata1 
1 2 3 

Any ideas?


SOLVED

Thanks a lot!

1 Answers1

0

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!"

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;
Rick
  • 1,210
  • 6
  • 11