Making a 1001 assumptions here, I think one of these two programs is closer to what you're looking for - likely the second.
%let k_interims = 5;
%let n_1 = 10;
%let n_2 = 10;
%let n_3 = 10;
%let n_4 = 10;
%let n_5 = 10;
%let i_nullprop_mean = 0.5;
%let i_nullprop_SD = 0.1;
%let j_alternative_mean = 0.5;
%let j_alternative_SD = 0.1;
proc datasets lib=work;
delete count_:;
run;quit;
options mprint symbolgen;
*expand dataset exponentially;
%macro loop (n=);
%do i=1 %to &n;
data count_&i.;
length trt sbi 4;
%if &i ne 1 %then
%do;
set count_%eval(&i-1);
%end;
do j=1 to &&n_&i;
if mod(j, 2) eq 0 then
do;
trt=1;
sbi=rand("Bernoulli", abs(rand("Normal", &j_alternative_mean,
&j_alternative_SD)));
end;
else
do;
trt=0;
sbi=rand("Bernoulli", abs(rand("Normal", &i_nullprop_mean,
&i_nullprop_SD)));
end;
output;
end;
run;
%end;
%mend;
%loop(n=&k_interims);
Appends data sets together;
proc datasets lib=work;
delete count_:;
run;quit;
*appends each dataset together at the end for the last dataset to have 50 rows;
%macro loop (n=);
%do i=1 %to &n;
data count_&i.;
length trt sbi 4;
do j=1 to &&n_&i;
if mod(j, 2) eq 0 then
do;
trt=1;
sbi=rand("Bernoulli", abs(rand("Normal", &j_alternative_mean,
&j_alternative_SD)));
end;
else
do;
trt=0;
sbi=rand("Bernoulli", abs(rand("Normal", &i_nullprop_mean,
&i_nullprop_SD)));
end;
output;
end;
run;
%if &i ne 1 %then
%do;
proc append base=count_&i data=count_%eval(&i-1);
run;
%end;
%end;
%mend;
%loop(n=&k_interims);
@LuGa wrote:
Dear SAS Gurus,
please help me debugging my loop.
%let k_interims = 5;
%let n_1 = 100;
%let n_2 = 100;
%let n_3 = 100;
%let n_4 = 100;
%let n_5 = 100;
%let i_nullprop_mean = 0.5;
%let i_nullprop_SD = 0.1;
%let j_alternative_mean = 0.5;
%let j_alternative_SD = 0.1;
data _null_;
do i=1 to &k_interims by 1;
s= '
data count_'||trim(left(put(i,3.)))||' (drop=j);
length trt sbi 4;
if '||trim(left(put(i,3.)))||' eq "1" or '||trim(left(put(i,3.)))||' eq 1 then do;
do j = 1 to round(&n_'||trim(left(put(i,3.)))||', 2) by 1;
if mod(j, 2) eq 0 then do;
trt = 1;
sbi = rand("Bernoulli", abs(rand("Normal", &j_alternative_mean, &j_alternative_SD)));
end;
else do;
trt = 0;
sbi = rand("Bernoulli", abs(rand("Normal", &i_nullprop_mean, &i_nullprop_SD)));
end;
output;
end;
end;
else if '||trim(left(put(i,3.)))||' ne "1" or '||trim(left(put(i,3.)))||' ne 1 then do;
set count_'||trim(left(put(i-1, 3.)))||';
do j = 1 to round(&n_'||trim(left(put(i,3.)))||', 2) by 1;
if mod(j, 2) eq 0 then do;
trt = 1;
sbi = rand("Bernoulli", abs(rand("Normal", &j_alternative_mean, &j_alternative_SD)));
end;
else do;
trt = 0;
sbi = rand("Bernoulli", abs(rand("Normal", &i_nullprop_mean, &i_nullprop_SD)));
end;
output;
end;
end;
run;
';
call execute(s);
end;
run;
results in right at the first if statement for the case that i=1:
ERROR: File WORK.COUNT_0.DATA does not exist.
I don't understand why SAS does not accept the case:
if '||trim(left(put(i,3.)))||' eq "1" or '||trim(left(put(i,3.)))||' eq 1 then do;
As you can see I tried to resolve by handling i as a character.
In python I would simply put a:
print(i)
in between the loop.
How is it possible to debug such cases?
THX and BR
Lukas
... View more