turn on suggestions

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

Showing results for

Find a Community

Topic Options

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

10-23-2017 11:27 AM

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

Accepted Solutions

Solution

10-23-2017
12:18 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rick_SAS

10-23-2017 12:15 PM

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to _bc_

10-23-2017 11:38 AM

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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to _bc_

10-23-2017 11:43 AM

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

Solution

10-23-2017
12:18 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rick_SAS

10-23-2017 12:15 PM