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

 

I receive this message "ERROR: Invocation of unresolved module TRAPINTEGRAL." I am not sure why I got this message ? I am attaching my data file along with my SAS code.

Thanks for helping

 

 

proc iml;

start Gama(k) global(m,R);
s1=0;
do j=k to m;
s1=s1+(R[j]+1);
end;
return(s1);
finish;

********************************;
***** Trapezoidal Method *******;
********************************;

start TrapIntegral(x,y);
N = nrow(x);
dx = x[2:N] - x[1:N-1];
meanY = ( y[2:N] + y[1:N-1] )/2;
return( dx` * meanY );

finish;

*********************************************************************************************************;

libname lib "C:\Users\amal\Dropbox\Rola-PHD\Kernel\Hani Real Life Data";


* One way to read the data in SAS;

data lomax;
set lib.lomaxnew;
WP_grid=(Y-X);
run;

proc iml;

*** To use the Data in SAS/IML we need to write "use", "read", and "close";
Use Lomax;
read all var {WP_grid};
Close Lomax;

m=nrow(WP_grid);



************************;
*** Complete Data ***;
************************;

create A_p var {"WP_grid"};
append;
close A_p;

submit;

Data A_P1;
set A_p;
run;

proc kde data=A_p1 out=prog_data gridl=0.1 gridu=2 method=srot;
var WP_grid ;
run;
endsubmit;

Use prog_data;
read all var {WP_grid density};
Close prog_data;


Area_p= TrapIntegral(WP_grid , density);* the estiamted value of R is the area under the curve;

print Area_p;

quit;

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

You get the error because you did not save the module TRAPINTEGRAL. If you do not save the module, SAS can't remember it after an IML step. Read the blog post Storing and loading modules to learn more. 

 

Alternatively you can simply define the module in the relevant IML step like below. Also, I don't see a reason to use the Submit/Endsubmit Statements here. As I see it, you can just as well run PROC KDE on you Lomax data set.


See if the below code helps you. I took the first 20 rows of data from your example data set and put them in a data step for testing.

 

data lomaxnew;
input Y X;
datalines;
1.22 0.01
1.24 0.01
1.8 0.01
1.27 0.02
1.03 0.13
1.67 0.18
1 0.19
1.07 0.2
1.1 0.21
0.78 0.22
0.99 0.23
0.89 0.24
0.93 0.25
0.98 0.25
1.25 0.26
1.2 0.27
1.31 0.27
1.19 0.29
1.23 0.29
1.25 0.29
;

data lomax;
set lomaxnew;
WP_grid=(Y-X);
run;

proc kde data=lomax out=prog_data gridl=0.1 gridu=2 method=srot;
   var WP_grid ;
run;

proc iml;

start TrapIntegral(x,y);
N = nrow(x);
dx = x[2:N] - x[1:N-1];
meanY = ( y[2:N] + y[1:N-1] )/2;
return( dx` * meanY );
finish;

Use prog_data;
read all var {WP_grid density};
Close prog_data;

Area_p= TrapIntegral(WP_grid , density);

print Area_p;

quit;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

You get the error because you did not save the module TRAPINTEGRAL. If you do not save the module, SAS can't remember it after an IML step. Read the blog post Storing and loading modules to learn more. 

 

Alternatively you can simply define the module in the relevant IML step like below. Also, I don't see a reason to use the Submit/Endsubmit Statements here. As I see it, you can just as well run PROC KDE on you Lomax data set.


See if the below code helps you. I took the first 20 rows of data from your example data set and put them in a data step for testing.

 

data lomaxnew;
input Y X;
datalines;
1.22 0.01
1.24 0.01
1.8 0.01
1.27 0.02
1.03 0.13
1.67 0.18
1 0.19
1.07 0.2
1.1 0.21
0.78 0.22
0.99 0.23
0.89 0.24
0.93 0.25
0.98 0.25
1.25 0.26
1.2 0.27
1.31 0.27
1.19 0.29
1.23 0.29
1.25 0.29
;

data lomax;
set lomaxnew;
WP_grid=(Y-X);
run;

proc kde data=lomax out=prog_data gridl=0.1 gridu=2 method=srot;
   var WP_grid ;
run;

proc iml;

start TrapIntegral(x,y);
N = nrow(x);
dx = x[2:N] - x[1:N-1];
meanY = ( y[2:N] + y[1:N-1] )/2;
return( dx` * meanY );
finish;

Use prog_data;
read all var {WP_grid density};
Close prog_data;

Area_p= TrapIntegral(WP_grid , density);

print Area_p;

quit;
Salah
Quartz | Level 8

Thank you for your help. 

 

 

Rick_SAS
SAS Super FREQ

For readers who are curious about what the OP is doing, see my blog post on "The area under a density estimate curve."

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2999 views
  • 3 likes
  • 3 in conversation