14,421,160 members

See more:

Hi!

I would like to convert the below SAS code into R code. It would be great help for me!

Thanks in advance!

%let NN=1000;

proc iml;

cov={1 .1 .1 .1 .1,

.1 1 .1 .1 .1,

.1 .1 1 .1 .1,

.1 .1 .1 1 .1,

.1 .1 .1 .1 1

};

M=5;

h={[5].2};

Rcvr={[5].2};

T={[&NN]0};

VL={[&NN]0};

VR={[&NN]0};

s={[&NN]0};

r=0.05;

rv=rannor(repeat(1200,&NN,5));

Y=rv*(root(cov));

spread=0;

i=1;

j=1;

do while (i<=&NN);

do while (j<=5);

x=cdf('Normal',Y[i,j]);

Y[i,j]= -(log(1-x))/h[j];

j=j+1;

end;

T[i]=min(Y[i,]);

j=1;

k=0.5;

do while (k<T[i] & k<=M);

VL[i]=VL[i]+EXP(-r*k);

k=k+0.5;

end;

do while(j<=5);

if (T[i]=Y[i,j] & T[i]<M) then VR[i]=VR[i]+(1-Rcvr[j])*(EXP(-r*T[i]));

j=j+1;

end;

j=1;

if VL[i]^=0 then s[i]=VR[i]/VL[i];

spread=spread+s[i];

i=i+1;

end;

spread=spread/&NN;

print spread;

run;

quit;

**What I have tried:**

I stucked in some steps in my effort to translate the code

I would like to convert the below SAS code into R code. It would be great help for me!

Thanks in advance!

%let NN=1000;

proc iml;

cov={1 .1 .1 .1 .1,

.1 1 .1 .1 .1,

.1 .1 1 .1 .1,

.1 .1 .1 1 .1,

.1 .1 .1 .1 1

};

M=5;

h={[5].2};

Rcvr={[5].2};

T={[&NN]0};

VL={[&NN]0};

VR={[&NN]0};

s={[&NN]0};

r=0.05;

rv=rannor(repeat(1200,&NN,5));

Y=rv*(root(cov));

spread=0;

i=1;

j=1;

do while (i<=&NN);

do while (j<=5);

x=cdf('Normal',Y[i,j]);

Y[i,j]= -(log(1-x))/h[j];

j=j+1;

end;

T[i]=min(Y[i,]);

j=1;

k=0.5;

do while (k<T[i] & k<=M);

VL[i]=VL[i]+EXP(-r*k);

k=k+0.5;

end;

do while(j<=5);

if (T[i]=Y[i,j] & T[i]<M) then VR[i]=VR[i]+(1-Rcvr[j])*(EXP(-r*T[i]));

j=j+1;

end;

j=1;

if VL[i]^=0 then s[i]=VR[i]/VL[i];

spread=spread+s[i];

i=i+1;

end;

spread=spread/&NN;

print spread;

run;

quit;

I stucked in some steps in my effort to translate the code

Comments

Sorry, this site does not provide code, or code conversion, to order.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject,
503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada
+1 416-849-8900 x 100