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.

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

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