I interpreted your question a bit differently than @Ksharp and @FreelanceReinh (...which is daring...).
I believe the formula to calculate the survival rate for a student after n semesters with a drop out probability p of 0.1 per semesters would be: S(n) = (1-p) n
I couldn't figure out a way that doesn't require a loop for calculating the drop out semester. Soo.... here I go:
%let n_semesters=13;
%let drop_probability=0.1;
data have;
do semester=1 to &n_semesters;
do i=1 to 10000;
student_id=cats(semester,'_',i);
output;
end;
end;
drop i;
run;
data want;
set have;
if _n_=1 then call streaminit(1230497);
drop_out_flg=0;
do i=1 to semester;
if rand('uniform')<=&drop_probability then
do;
drop_out_flg=1;
drop_out_semester=i;
leave;
end;
end;
run;
%let sv_missing=%sysfunc(getoption(missing,keyword));
options missing=' ';
title 'drop/no drop per semester';
proc tabulate data=want noseps missing;
keylabel n=' ';
class drop_out_flg drop_out_semester;
table drop_out_semester all='Total', drop_out_flg;
run;
title;
options &sv_missing;
/* as a check: calculate survival for a student over all remaining semesters */
%let sv_missing=%sysfunc(getoption(missing,keyword));
options missing=' ';
data survival;
set have;
if _n_=1 then call streaminit(1230497);
drop_out_flg=0;
if rand('uniform')>(1-&drop_probability)**semester then drop_out_flg=1;
run;
title 'survival over all semesters';
proc tabulate data=survival noseps missing;
keylabel n=' ';
class drop_out_flg;
table drop_out_flg;
run;
title;
... View more