Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 10-23-2017 11:27 AM
(882 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

3 REPLIES 3

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

📢

**ANNOUNCEMENT**

The early bird rate has been extended! Register by March 18 for just $695 - $100 off the standard rate.

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.** **

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.