Statistical programming, matrix languages, and more

Question for SAS IML function

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

Question for SAS IML function

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! 


Accepted Solutions
Solution
3 weeks ago
SAS Super FREQ
Posts: 3,475

Re: Question for SAS IML function

[ Edited ]

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


All Replies
Solution
3 weeks ago
SAS Super FREQ
Posts: 3,475

Re: Question for SAS IML function

[ Edited ]

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.

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 168 views
  • 2 likes
  • 2 in conversation