14,421,160 members
Rate this:
See more:
Hi!

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

%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));
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];
i=i+1;
end;
run;
quit;

What I have tried:

I stucked in some steps in my effort to translate the code
Posted
Updated 26-Apr-18 0:09am
Richard MacCutchan 26-Apr-18 5:01am

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

Rate this:

## Solution 1

We do not provide a code conversion service, and code conversion rarely produces good code in the target language anyway: either learn SAS plus R and convert it yourself, work out what the SAS code is doing and recode that functionality in R, or find R code that does the same job.

Top Experts
Last 24hrsThis month
 OriginalGriff 304 phil.o 105 Richard MacCutchan 90 CHill60 60 Maciej Los 40
 OriginalGriff 3,913 Richard MacCutchan 1,376 phil.o 770 Patrice T 764 Maciej Los 720

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