BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jazhang
Fluorite | Level 6
proc IML;
a=1;
b=2;
start sum_square(c,a,b);
a = a+1;
c = (a+b)**2;
finish;

run sum_square(c,a,b);
print a c;

 

I found an issue with the SAS IML function that the input value of the function would be changed if the input value is overrided inside the function. In the example code, I actually do not want to modify the value of "a" after the function is run, however, "a" is changed to 2 when I print at the bottom of the code. Is there anyway that I can avoid to override the input? In matlab, the input value would not change even if it is modified in a function. Thanks! 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

Yes. Every argument to an IML module can be modified inside the module. For a discussion see "Passing arguments by reference: An efficient choice."  The last section of the same article discusses how a programmer that is creating a module can make sure that input arguments are not modified. In your example, the technique would be 

 

start sum_square(c,_a,b);
a = _a+1;
c = (a+b)**2;
finish;

 The SAS/IML documentation also contains an example and discussion of passing arguments by reference.

 

View solution in original post

1 REPLY 1
Rick_SAS
SAS Super FREQ

Yes. Every argument to an IML module can be modified inside the module. For a discussion see "Passing arguments by reference: An efficient choice."  The last section of the same article discusses how a programmer that is creating a module can make sure that input arguments are not modified. In your example, the technique would be 

 

start sum_square(c,_a,b);
a = _a+1;
c = (a+b)**2;
finish;

 The SAS/IML documentation also contains an example and discussion of passing arguments by reference.

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 1 reply
  • 1286 views
  • 2 likes
  • 2 in conversation