/*-------------------------------------------------------------------*/ /* Debugging SAS Programs: A Handbook of Tools and Techniques */ /* by Michele M. Burlew */ /* Copyright(c) 2001 by SAS Institute Inc.

, Cary, NC, USA */ /* SAS Publications order # 57743 */ /* ISBN 1-58025-927-8 */ /*-------------------------------------------------------------------*/ /* */ /* This material is provided "as is" by SAS Institute Inc. There */ /* are no warranties, expressed or implied, as to merchantability or */ /* fitness for a particular purpose regarding the materials or code */ /* contained herein. The Institute is not responsible for errors */ /* in this material as it now exists or will exist, nor does the */ /* Institute provide technical support for it. */ /* */ /*-------------------------------------------------------------------*/ /* Questions or problem reports concerning this material may be */ /* addressed to the author: */ /* */ /* SAS Institute Inc. */ /* Books by Users */ /* Attn: Michele Burlew */ /* SAS Campus Drive */ /* Cary, NC 27513 */ /* */ /* */ /* If you prefer, you can send email to: sasbbu@sas.com */ /* Use this for subject field: */ /* Comments for Michele Burlew */ /* */ /*-------------------------------------------------------------------*/ /* Date Last Updated: 22OCT01 */ /*-------------------------------------------------------------------*/ /***************************************************************/ /* This data set contains information about the items in */ /* circulation from the corporate library. The DATA step */ /* generates 446 observations by using DO loops and random */ /* number functions to fabricate the data. It obtains */ /* information from CORPLIB.ITEMS and CORPLIB.EMPLOYEES to */ /* retain in the observations. */ /***************************************************************/ data corplib.circul(label='Corporate Library Circulation'); attrib itemid copynum length=$10 label='Library Book Id' length=4 format=2. label='Copy Number' checkout length=8 informat=mmddyy10. format=mmddyy10. label='Check Out Date' duedate length=8 informat=mmddyy10. format=mmddyy10. label='Due Date' empno length=8 label='Employee Number' format=z6. canrenew length=$1 label='Item Can be Renewed' nrenew length=3 label='Number of Renewals' checkin length=8 informat=mmddyy10.

if nrenew > 1 then canrenew='N'. /* Obtain the total number of items in ITEMS data set */ dsid=open('corplib. r=round(30*uniform(55)+1.).18)=1 then canrenew='N'. checkout=datejul(2000000+d). run.15.items').. */ /***************************************************************/ . /* Obtain the total number of emps in EMPLOYEES data set */ dsid=open('corplib. rc=close(dsid). nemps=attrn(dsid.format=mmddyy10.29) then checkin=checkout+d+r. else checkin=. nrenew=0.items(keep=itemid copynum) point=getobs.32)=1 then nrenew=nrenew+1.28. if mod(i. if mod(i. do i=1 to 446. nitems=attrn(dsid. end. /* Randomly pick an item from the ITEMS data set */ getobs=nitems*uniform(21)+1.'NOBS'). The DATA */ /* step generates 5 observations by using DO loops and random */ /* number functions to fabricate the data. set corplib.46)=1 then nrenew=nrenew+1.'NOBS'). /* Stop at 446 observations */ if i ge 446 then stop. /* Randomly determine a checkout date */ d=round(185*uniform(44)+1. rc=close(dsid).7. drop i d dsid rc nemps nitems r. label='Check In Date' . set corplib. duedate=checkout+30.).employees'). /* Randomly pick an employee from the EMPLOYEES data set who will be assigned the item */ getobs=nemps*uniform(22)+1. if mod(i. if mod(i. /***************************************************************/ /* This data set contains information about the distributors */ /* from whom the corporate library purchases items.11. /* Assign a few as multiple renewals and as items that cannot be renewed */ canrenew='Y'.16.employees(keep=empno) point=getobs. /* Assign a few checkouts to be checked in */ if r in (3.1. output.1.88)=1 then nrenew=nrenew+1.

end. run. distaddr='Distributor ' || put(i. distzip=13021. if i=1 then do. else if i=5 then do. distcity='Distributor ' || put(i. distfax=9255555555. diststat='IL'. distzip=94000. The DATA step generates 3.). */ length=$4 length=$25 length=$30 length=$25 length=$2 length=8 length=8 length=8 label='Distributor label='Distributor label='Distributor label='Distributor label='Distributor label='Distributor label='Distributor label='Distributor ID' Name' Address' City' State' Zip Code' Phone Number' Fax Number'. end. do i=1 to 5. end.distrib(label='Book Distributors').1. distphon=6515555555. distphon=3125555555. diststat='NY'.z3. . end. distzip=55100. distname='Distributor ' || put(i.). distfax=3155555555. distphon=9255555555. diststat='CA'. distzip=19000.). diststat='PA'. diststat='MN'. else if i=2 then do. distfax=3125555555. attrib distid distname distaddr distcity diststat distzip distphon distfax drop i. distfax=6515555555. /***************************************************************/ /* This data set contains information about the employees of */ /* the corporation. distid='D' || put(i. else if i=3 then do. end.data corplib.1. distphon=2155555555. else if i=4 then do. end. distzip=60000. output. distfax=2155555555.210 observations */ /* by using DO loops and random number functions to fabricate */ /* the data. distphon=3155555555.).1.

end. empfn='First' || left(put(i.3)=0 then do. empphone=9935555550+i.750 */ /* observations by using DO loops and random number functions */ /* to fabricate the data. empzip=14000+m. empstate='NJ'. empzip=61100+m. drop i m. run. attrib empno length=8 format=z4. empln length=$25 empfn length=$15 empaddr length=$35 empcity length=$25 empstate length=$2 empzip length=8 empphone length=8 empdept length=8 format=z6. empphone=7165555550+i. empcity='City ' || left(put(m. empzip=30000+m.2)=0 then do. /***************************************************************/ /* This data set contains information about the items in the */ /* corporate library. empstate='NY'. empstate='GA'. empaddr=put(1000*uniform(25)./***************************************************************/ data corplib. empzip=00000+m.) || ' Address Road'. .items(label='Corporate Library Items'). */ /***************************************************************/ data corplib. The DATA step generates 3. m=mod(i. end.1. empln='Last' || left(put(i. else if mod(m.4.)). end. label='Employee Number' label='Employee label='Employee label='Employee label='Employee label='Employee label='Employee label='Employee label='Employee Last Name' First Name' Address' City' State' Zip Code' Phone' Department' .8)+1. end. end.5)=0 then do. else if mod(m.employees(label='Corporate Employees'). empno=1000+i.3. empphone=4045555550+i.3.)). empstate='IL'. /* Generate 3210 employees */ do i=1 to 3210. if mod(m. else do. empphone=6095555550+i. output.)).

3. array sect{6} sect1-sect6. /* Generate multiple copies of selected items */ .1).)). /* Randomly generate 3000 items in the library */ do i=1 to 3000.). Number' label='Call Number' label='Publisher' label='City where Published' label='Year Published' label='Library Section' label='Type of Material' orderdat length=8 informat=mmddyy10. label='Order Date' ordernum length=3 label='Order Number' itemcost length=8 format=dollar6. output.)). pubcity='City ' || left(put(p.z4. format=mmddyy10.)). else if m=6 then itemtype='S'. else if m=1 then itemtype='R'. label='Subscription Renewal Date' .2 label='Cost of Item' subscdat length=8 informat=mmddyy10. First' || left(put(i.2. itemid='LIB' || put(1000*uniform(100). p=10*uniform(5).2.6)+1. copynum=1.attrib itemid title author copynum length=$10 length=$100 length=$50 length=4 label='Copy callnum length=8 format=7. author='Last' || left(put(i.)). publish='Publisher ' || left(put(p.3.1.2 publish length=$50 pubcity length=$50 pubyear length=4 libsect length=$11 itemtype length=$1 label='Library Book Id' label='Title' label='Author' format=2. drop i m p sect1-sect6. retain sect1 'Reference' sect2 'Science' sect3 'Business' sect4 'Computers' sect5 'General' sect6 'Serials'. /* Assign a material type to the item */ if 2 le m le 5 then itemtype='B'.)) || '.3. pubyear=1995 + round(p. libsect=sect{m}. ormat=mmddyy10. /* Assign a library section to the item */ m=mod(i. title='Title ' || left(put(i. callnum=4000*uniform(10)*.

end. if mod(i. end. if mod(i. libsect=sect{m}.1. keep ordernum ordrdate nitems distid ordertot datercvd . end. */ /***************************************************************/ data corplib. output. output. distid length=$4 label='Distributor ID' . /***************************************************************/ /* This data set contains information about the orders placed */ /* by the corporate library. if 2 le m le 5 then itemtype='B'. copynum=copynum+1. else if m=6 then itemtype='S'. output. output. ordrdate informat=mmddyy10. copynum=copynum+1. end. p=10*uniform(4). pubyear=1995 + round(p.3.2.)).16)=1 then do. copynum=copynum+1. end.44)=1 or mod(i.34)=1 then do.if mod(i. if mod(i.16)=1 then do. output. else if m=1 then itemtype='R'.)). title='Title 2-' || left(put(i. label='Order Date' nitems label='Number of Items Ordered' format=4. run. output. copynum=copynum+1.2. The DATA step generates 53 */ /* observations by using DO loops and random number functions */ /* to fabricate the data.orders(label='Corporate Library Orders').)).34)=1 then do.6)+1. if mod(i. output. if mod(i. attrib ordernum label='Order Number' format=z4.z4. callnum=4000*uniform(10)*.). end. copynum=1. copynum=copynum+1. format=mmddyy10. end. pubcity='City ' || left(put(p.22)=1 then do. publish='Publisher ' || left(put(p. itemid='LIB' || put(1000*uniform(99). copynum=copynum+1. end. if mod(i. m=mod(i.1).32)=1 then do.22)=1 then do.

. ordertot label='Order Total' format=dollar10. distid='D' || put(dnum. /* Generate 53 orders */ do ordernum=1 to 53.. run. ordertot=nitems*avgprice. output.3)=1 then dnum=2.53) then datercvd=ordrdate+int(60*uniform(66)). end. label='Date Order Received' /* Set starting date */ baseval='31DEC1998'd. /* Determine a distributor id for the order */ dnum=int(5*uniform(55))+1. if mod(ordernum. /* Determine the number of items and average price per item for the order */ nitems=int(20*uniform(22))+1..). baseval=ordrdate.z3.48. avgprice=(20*uniform(222))+20. if ordernum not in (37.51.2 datercvd informat=mmddyy10. format=mmddyy10. else datercvd=. /* Determine a date for the order */ ordrdate=baseval+int(30*uniform(33)).50.