BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
_bc_
Calcite | Level 5

I want to pass the name of a function to another function as an argument in IML.  Is this possible? I'm running V9.4

 

proc iml;

   start try1(x,y);
   return(x+y);
   finish;

   start try2(x,y);
   return (x*y);
   finish;

   start calc(x,y,func);
   return ( func(x,y) );
   finish;

  x=2; y=3;
  a = calc(x,y,"try1"); print a;
  b = calc(x,y,"try2"); print b;

quit;
1 ACCEPTED SOLUTION

Accepted Solutions
_bc_
Calcite | Level 5

Yes, I see.  I did not know of either of these two strategies.  Perfectly clear answer with your examples.  Thanks very much for the information.  A great help.

View solution in original post

3 REPLIES 3
Rick_SAS
SAS Super FREQ

Maybe. It depends what you are trying to do. Look at the APPLY function, which solves your trivial example. 

 

proc iml;
   start try1(x,y);
   return(x+y);
   finish;

   start try2(x,y);
   return (x*y);
   finish;

  x=2; y=3;
  a = apply("try1", x,y); print a;
  b = apply("try2", x,y); print b;
Rick_SAS
SAS Super FREQ

I guess the general answer is that you can build the function call as a text string and then use CALL EXECUTE to call the function:

 

start calc(x,y,func);
   z = .;
   cmd = "z = " + func + "(x,y);";
   call execute( cmd );
   return z;
finish;

x=2; y=3;
a = calc(x,y,"try1"); print a;
b = calc(x,y,"try2"); print b;
_bc_
Calcite | Level 5

Yes, I see.  I did not know of either of these two strategies.  Perfectly clear answer with your examples.  Thanks very much for the information.  A great help.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 917 views
  • 3 likes
  • 2 in conversation