Turn on suggestions

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

Showing results for

- Home
- /
- Programming
- /
- Programming
- /
- Re: IML Without IML installed

Options

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

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

Posted 09-10-2020 11:34 AM
(723 views)

I work in a world with SAS on the desktop and SAS on a server. Unfortunately they do not have all of the same PROCs licensed on both platforms. We do not have the budget to add IML to the server so I am reaching out to the community. I myself have never worked with IML, but some of the other departments that place tools on the server do use IML. I need help deconstructing the following code to just SAS, we have STAT/OR/QC/ETS on both platforms.

Is there a way to do this with a different set of PROCs?

```
proc iml;
R=0.4;
p1=0.5;
p2=0.5;
p3=0.5;
start Q1f(t);
alpha1=1; alpha2=2; alpha3=2;
shape1=2; shape2=3; shape3=1.5;
v1=cdf("WEIBULL",t, shape1, alpha1);
v2=cdf("WEIBULL",t, shape2, alpha2);
v3=cdf("WEIBULL",t, shape3, alpha3);
Q1=PDF("WEIBULL",t, shape1, alpha1)*(1-v2)*(1-v3);
return(Q1);
finish;
start Q2f(t);
alpha1=1; alpha2=2; alpha3=2;
shape1=2; shape2=3; shape3=1.5;
v1=cdf("WEIBULL",t, shape1, alpha1);
v2=cdf("WEIBULL",t, shape2, alpha2);
v3=cdf("WEIBULL",t, shape3, alpha3);
Q2=PDF("WEIBULL",t, shape2, alpha2)*(1-v1)*(1-v3);
return(Q2);
finish;
start Q3f(t);
alpha1=1; alpha2=2; alpha3=2;
shape1=2; shape2=3; shape3=1.5;
v1=cdf("WEIBULL",t, shape1, alpha1);
v2=cdf("WEIBULL",t, shape2, alpha2);
v3=cdf("WEIBULL",t, shape3, alpha3);
Q3=PDF("WEIBULL",t, shape3, alpha3)*(1-v1)*(1-v2);
return(Q3);
finish;
a = {0 .P };
call quad(Z1, "Q1f", a);
call quad(Z2, "Q2f", a);
call quad(Z3, "Q3f", a);
print Z1[format=E16.6] Z2[format=E16.6] Z3[format=E16.6];
p_task=Z1*p1+Z2*p2+Z3*p3;
R_equiv=R/(1-p_task);
print p_task[format=E16.6] R_equiv[format=E16.6];
run;
quit;
```

5 REPLIES 5

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

Evaluating functions Q1f Q2f and Q3f can all be done in DATA step code, because the functions CDF() and PDF() work in data steps as well. The hard part would be replacing CALL QUAD in PROC IML, which is doing numerical integration of these three functions. I'm not really aware of another way to do numerical integration of a function in SAS. I suppose you could write your own DATA step code to do this, but that sounds pretty difficult to do, and difficult to verify its accuracy. I suppose you could send the output of the functions to R (or MATLAB) and do the numerical integration there and send the results back to SAS, as routines to do numerical integration of functions exist in R and MATLAB. None if it sounds easy or quick. Good luck.

--

Paige Miller

Paige Miller

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

Hi @TBarney,

Regarding the "hard part," CALL QUAD, I've just found in the documentation that this CALL routine is available (as a programming statement) in PROC MCMC (SAS/STAT).

This is my first attempt at (mis)using PROC MCMC as a numerical integrator:

```
/* Define the integrand function in the form of a subroutine */
proc fcmp outlib=work.funcs.stats;
subroutine testfct(x,y);
outargs y;
y=pdf('normal',x);
endsub;
run;
options cmplib=work.funcs;
/* Create a non-empty input dataset */
data dummy;
_=.;
run;
/* Integrate the function numerically in a dummy PROC MCMC step */
proc mcmc data=dummy;
parms z;
prior z ~ general(0);
call quad("testfct",result,-probit(0.95),probit(0.95));
put result=;
stop;
model general(0);
run;
```

The result is written to the output window

result=0.8999999993

and is very close to the known exact value (0.9).

You may want to suppress the note "The SAS System stopped processing this step because of errors" in the log, e.g., by using options nonotes.

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

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

@FreelanceReinh thanks, I learn something new every day! I hate it when that happens 😉

--

Paige Miller

Paige Miller

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

@PaigeMiller wrote:

@FreelanceReinh thanks, I learn something new every day!

You're welcome. Same here. I had never heard of CALL QUAD before today, let alone did I know it was available in one of the few SAS modules I've licensed. And I've never used PROC MCMC in practice.

**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.

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.