Thanks a million works like a dream. Easy to forget these nice functions that have been around since forever, Here is the revised code. %let avg_mnth=15;
data WORK.CUM_PROB;
infile datalines dsd truncover;
input Proportion:BEST10.9 hrs_draw:32. cum:32.;
datalines4;
0.51818182,6,0.5181818182
0.05909091,7,0.5772727273
0.21363636,10,0.7909090909
0.20909091,18,1
;;;;
run;
data to_fmt;
set cum_prob;
retain start end;
prev=lag(proportion);
if _n_=1 then do;
start=0;
end=proportion;
SEXCL='N';
end;
else do;
start=end;
end=start+proportion;
sexcl='Y';
end;
label=put(hrs_draw,best.);
type='I';
fmtname='hrsval';
run;
proc format cntlin=to_fmt;
run;
Data events;
prob_by_day=30/&avg_mnth;
do i=0 to 5000 by 1;
date = intnx('day','01jul2017'd,i);
p=rand('POISSON',1/prob_by_day);
if p > 0 then do;
do j=1 to p by 1;
draw=rand('UNIFORM');
hrs=input(draw,hrsval.);
c=1;
output;
end;
end;
else do;
draw =.;
hrs=.;
c=0;
output;
end;
end;
drop j;
format date date9.;
run;
... View more