******************************************* * DISCRETE RANDOM VARIABLE SIMULATION * * * * DSN= DSIMINV.SAS * *******************************************; data dsiminv1; do i=1 to 10; week = i; order = 0; exdmd = 0; ddue0=0; ddue1=0; ddue2=0; ddue3=0; ddue4=0; TC = 0; CO = 0; CC = 0; CS = 0; if i=1 then beginv=20; if i gt 1 then beginv = endinv; if i=1 then ordrec=0; if i=1 then due0=0; if i=1 then due1=0; if i=1 then due2=0; if i=1 then due3=0; if i=1 then due4=0; ddue0=due0; ddue1=due1; ddue2=due2; ddue3=due3; ddue4=due4; due0=ddue1; due1=ddue2; due2=ddue3; due3=ddue4; due4=0; q = 40; r = 30; if i=1 then r1 = 00; if i=1 then r2=46; if i=2 then r1 = 49; if i=2 then r2=80; if i=3 then r1 = 41; if i=3 then r2=61; if i=4 then r1 = 94; if i=4 then r2=89; if i=5 then r1 = 87; if i=5 then r2=47; if i=6 then r1 = 33; if i=6 then r2=.; if i=7 then r1 = 67; if i=7 then r2=.; if i=8 then r1 = 44; if i=8 then r2=.; if i=9 then r1 = 63; if i=9 then r2=.; if i=10 then r1 = 25; if i=10 then r2=.; if r1 le 19 then demand = 14; if r1 le 59 and r1 gt 19 then demand = 15; if r1 le 79 and r1 gt 59 then demand = 16; if r1 le 89 and r1 gt 79 then demand = 17; if r1 le 99 and r1 gt 89 then demand = 18; if r2 le 59 then ldtime = 2; if r2 le 89 and r2 gt 59 then ldtime = 3; if r2 le 99 and r2 gt 89 then ldtime = 4; if r2 = . then ldtime = .; ordrec = due0*40; invlvl = beginv + ordrec; endinv = invlvl - demand; if endinv lt 0 then endinv = 0; if demand > invlvl then exdmd = demand - invlvl; if endinv le 30 then order = 1; if order=1 and ldtime=2 then due2=due2+1; if order=1 and ldtime=3 then due3=due3+1; if order=1 and ldtime=4 then due4=due4+1; if endinv gt 30 then order = 0; if order=1 then CO = 150; CC = endinv; CS = exdmd * 100; TC = CO + CC + CS; output; end; proc print; var WEEK BEGINV ORDREC INVLVL R1 DEMAND ENDINV ORDER R2 LDTIME CO CC CS TC; title '10 week simulation results'; proc means; var TC ; data dsiminv2; do i=1 to 100; week = i; order = 0; exdmd = 0; ddue0=0; ddue1=0; ddue2=0; ddue3=0; ddue4=0; TC = 0; CO = 0; CC = 0; CS = 0; if i=1 then beginv=20; if i gt 1 then beginv = endinv; if i=1 then ordrec=0; if i=1 then due0=0; if i=1 then due1=0; if i=1 then due2=0; if i=1 then due3=0; if i=1 then due4=0; ddue0=due0; ddue1=due1; ddue2=due2; ddue3=due3; ddue4=due4; due0=ddue1; due1=ddue2; due2=ddue3; due3=ddue4; due4=0; q = 40; r = 30; r1 = int(ranuni(45)*100); r2 = int(ranuni(45)*100); if r1 le 19 then demand = 14; if r1 le 59 and r1 gt 19 then demand = 15; if r1 le 79 and r1 gt 59 then demand = 16; if r1 le 89 and r1 gt 79 then demand = 17; if r1 le 99 and r1 gt 89 then demand = 18; if r2 le 59 then ldtime = 2; if r2 le 89 and r2 gt 59 then ldtime = 3; if r2 le 99 and r2 gt 89 then ldtime = 4; ordrec = due0*40; invlvl = beginv + ordrec; endinv = invlvl - demand; if endinv lt 0 then endinv = 0; if demand > invlvl then exdmd = demand - invlvl; if endinv le 30 then order = 1; if order=1 and ldtime=2 then due2=due2+1; if order=1 and ldtime=3 then due3=due3+1; if order=1 and ldtime=4 then due4=due4+1; if endinv gt 30 then order = 0; if order=1 then CO = 150; CC = endinv; CS = exdmd * 100; TC = CO + CC + CS; output; end; proc print; var WEEK BEGINV ORDREC INVLVL R1 DEMAND ENDINV ORDER R2 LDTIME CO CC CS TC; title '100 week simulation results'; proc means; var TC ; run;