BookmarkSubscribeRSS Feed
TBarney
Fluorite | Level 6

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
PaigeMiller
Diamond | Level 26

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
FreelanceReinh
Jade | Level 19

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.

TBarney
Fluorite | Level 6

Thank you for this test.  The developers asking me for help are going to adapt this to their needs and see what they can do.

PaigeMiller
Diamond | Level 26

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

--
Paige Miller
FreelanceReinh
Jade | Level 19

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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 855 views
  • 11 likes
  • 3 in conversation