Programming the statistical procedures from SAS

NLMIXED Execution error for observation 1

Reply
New Contributor
Posts: 3

NLMIXED Execution error for observation 1

Hello Please, I simulated the data below, ran NLMIXED but had execution error. Any correction. 

 

/* Step 1: Generate a data set that contains many samples */
%let N = 500; /* sample size */
%let NumSamples = 3; /* number of samples */
data a;
call streaminit(1234);
do SampleID=1 to &NumSamples; /* ID variable for each sample */
do i = 1 to &N;
x1 = ranuni(1234);
x2 = ranuni(1234);
x3 = rannor(1234);
theta = 1;
mu = exp(1 + .3*x1 + .3*x2);
parm1 = 1/(1+mu/theta);
yneg = rand('NEGB',parm1,theta);
pzero = cdf('LOGISTIC',x3*2);
if ranuni(1234)>pzero then do;
ynegzim = yneg;
end;
else do;
ynegzim = 0;
end;
y=ynegzim;
output ;
end ;
end;
keep SampleID i y x1 x2;
run;
proc means data=a qntldef=3 q3;
by SampleID; var y;
output out=c;
run;
proc print data=a;
run;
/* Step 2: Compute the hurdle of each sample */
data a;
set a;
bound=c;
if y > bound then y=bound+1;
proc nlmixed data=a TECH=NEWRAP;
by SampleID;
parms a0=0 a1=0 a2=0 b0=0 b1=0 b2=0 alpha=0.5;
bounds alpha>0;
lin = a0 + a1*x1 + a2*x2;
w = exp(lin) / (1+exp(lin));
eta = b0 + b1*x1 + b2*x2;
mu = exp(eta);
phi = 1/alpha;
pdf = (gamma(y+phi)/(gamma(y+1)*gamma(phi)))
*((1/(1+alpha*mu))**phi*(alpha*mu/(1+alpha*mu))**y);
l_1 = w;
l_2 = (1-w)*pdf/ (1-(1+alpha*mu)**(-phi));
cdf=0;
do t=1 to c;
cdf=cdf+((1-w)*((gamma(t+phi)/(gamma(t+1)*gamma(phi)))
*((1/(1+alpha*mu))**phi*(alpha*mu/(1+alpha*mu))**t)/(1-(1+alpha*mu)**(-phi))));
end;
l_3= 1-cdf;
if y = 0 then ll = log(l_1);
if 0 < y <= bound then ll = log(l_2);
if y <= bound then d=0; else d=1;
ll=(1-d)*ll+d*log(l_3);
model y~general(ll);
ods output FitStatistics=OutStats;
run;
proc print data=OutStats;
run;

SAS Super FREQ
Posts: 3,547

Re: NLMIXED Execution error for observation 1

I think you made a mistake in Step 2.  You wrote:

 

/* Step 2: Compute the hurdle of each sample */
data a;
set a;
bound=c;
if y > bound then y=bound+1;
run;

 

However, there is no variable in data set A that is named c.  Therefore this DATA step results in assigning y=. (missing value) for all observations.

 

New Contributor
Posts: 3

Re: NLMIXED Execution error for observation 1

c as bound (censored point), c value is third quartile every number iD. can you help me to fix my syntax sas.
Ask a Question
Discussion stats
  • 2 replies
  • 285 views
  • 0 likes
  • 2 in conversation