*** SAS file generated by sastangle ***; options nocenter nodate nonumber ls=80 formdlim=''; *** Code chunk number 1 ***; data ds; do id = 1 to 8; x = normal(42); output; end; run; *** Code chunk number 2 ***; proc sort data=ds; by x; run; proc print data=ds; run; *** Code chunk number 3 ***; data smallest; set ds end=eof; /* eof is a variable; = 1 if last row */ retain smalldist last lastid smallid largeid; /* variables we keep between processing observations in the ds dataset */ if _n_ gt 1 then do; /* no diff for the first obs */ smalldist = min(smalldist, x - last); /* is distance smaller now than last time? */ if smalldist = x - last then do; /* if so */ smallid = lastid; /* the current smaller id is the one */ /* from the last row */ largeid = id; /* and the current larger id is the */ end; /* one in this row */ end; last = x; /* if this row turns out to be the */ lastid = id; /* smaller end of the smallest pair */ /* we'll need to know x and the id */ if eof then output; run; *** Code chunk number 4 ***; proc print data=smallest; var smalldist smallid largeid; run; *** Code chunk number 5 ***; data table (drop=j); array probs [11] prob0 prob1 - prob10; do p = .81 to .99 by .03; do j = 0 to 10; if j eq 1 then probs[j+1] = cdf("BINOMIAL", 0, p, 10); else probs[j+1] = cdf("BINOMIAL", j, p, 10) - cdf("BINOMIAL", j-1, p, 10); end; output; end; run; *** Code chunk number 6 ***; options ls=64; proc print data=table noobs; var p prob0 prob1 - prob10; format _numeric_ 3.2; run; *** Code chunk number 7 ***; libname k 'c:/temp'; *** Code chunk number 8 ***; data c_t4; set k.cauchy k.t4 (in=t4); if t4 then dist="t with 4 df"; else dist="Cauchy"; run; symbol1 i=j c=black l=1 w=3 v=none; symbol2 i=j c=black l=21 w=3 v=none; proc gplot data=c_t4; plot avex * i=dist / vref=0; run; quit; *** Code chunk number 9 ***; data fibo; do i = 1 to 10; fib = sum(fib, lag(fib)); if i eq 1 then fib = 1; output; end; run; proc print data=fibo; run; *** Code chunk number 10 ***; filename census1 "c:/book/co25_d00.dat"; data pcts cents; infile census1; retain cntyid; input @1 endind $3. @; /* the trailing '@' means to keep this line */ if endind ne 'END' then do; input @7 neglat $1. @; /* if this line does not say 'END', then check to see if the 7th character is '-' */ if neglat eq '-' then do; /* if so, it has a boundary point */ input @7 x y; const = 1; /* Used as choropleth value in the map */ output pcts; /* write out to boundary dataset */ end; else if neglat ne '-' then do; /* if not, it must be the centroid */ input @9 cntyid 2. x y ; output cents; /* write it to the centroid dataset */ end; end; run; *** Code chunk number 11 ***; filename census2 "c:/book/co25_d00a.dat"; data cntynames; infile census2 DSD; format cntyname $17. ; input cntyid 2. cntyname $; run; *** Code chunk number 12 ***; proc sort data=cntynames; by cntyid; run; proc sort data=cents; by cntyid; run; *** Code chunk number 13 ***; data nameloc; length function style color $ 8 position $ 1 text $ 20; retain xsys ysys "2" hsys "3" when "a"; merge cntynames cents; by cntyid; function="label"; style="swiss"; text=cntyname; color="black"; size=3; position="5"; output; run; *** Code chunk number 14 ***; pattern1 value=empty; proc gmap map=pcts data=pcts; choro const / nolegend coutline=black annotate=nameloc; id cntyid; run; quit; *** Code chunk number 15 ***; filename bike 'c:/book/cycle.csv'; proc import datafile=bike out=ride dbms=dlm; delimiter=','; getnames=yes; run; symbol1 c=black v=dot h=.5 i=none; axis1 color=white order = (-72.58,-72.461) offset=(0) value= (c=black) major = (c= black); axis2 color=white order = (42.315, 42.405) offset=(0) value= (c=black) major = (c= black); proc gplot data=ride; plot latitude * longitude / haxis=axis1 vaxis=axis2 imagestyle=fit iframe = "c:/book/mapback.jpeg"; ; run; *** Code chunk number 16 ***; proc import datafile="C:\book\usarrests.dta" out=usarrests dbms=dta replace; run; proc print data=usarrests (obs=5); run; *** Code chunk number 17 ***; goptions hsize = 4 in vsize = 4 in; pattern1 v=s c=grayff; pattern2 v=s c=grayda; pattern3 v=s c=grayaa; pattern4 v=s c=gray68; pattern5 v=s c=gray22; data mymap; set maps.us; region = lowcase(stnamel(statecode)); run; proc gmap data=usarrests map=mymap; id region; choro murder / levels=5; run; quit; *** Code chunk number 19 ***; filename salesdat url "http://www.amherst.edu/~nhorton/sasr2/datasets/cartoon.txt"; data sales; infile salesdat; retain dow month date time edt year; input @1 type $1 @; if type ne 's' then do; input @1 dow $ Month $ date time $ edt $ year; end; else do; input @12 rank; datetime = compress(date||month||year||"/"||time); salestime = input(datetime,datetime18.); if timepart(salestime) lt (8 * 60 * 60) or timepart(salestime) gt (18 * 60 * 60) then night=1; else night = 0; output; end; run; *** Code chunk number 20 ***; proc print data=sales (obs=4); var datetime salestime rank; run; *** Code chunk number 21 ***; proc print data=sales (obs=4); var datetime salestime rank; format salestime datetime18.; run; *** Code chunk number 22 ***; proc sgplot data=sales; series y=rank x=salestime / lineattrs=(thickness=2 color=black); scatter y=rank x=salestime / group=night grouporder=ascending markerattrs=(symbol=circlefilled) name="night"; refline "30SEP13/23:59:59"dt / axis=x lineattrs=(thickness=2 color=black pattern=shortdash); keylegend "night" / title="Night" location=inside position=top; xaxis label=" "; format salestime datetime8.; run; *** Code chunk number 26 ***; data one; wtpanacea=0.3; wtichor=0.2; wtgold=2.0; volpanacea=0.025; volichor=0.015; volgold=0.002; valpanacea=3000; valichor=1800; valgold=2500; maxwt=25; maxvol=0.25; /* find upper bound for looping */ maxpanacea = floor(min(maxwt/wtpanacea, maxvol/volpanacea)); maxichor = floor(min(maxwt/wtichor, maxvol/volichor)); maxgold = floor(min(maxwt/wtgold, maxvol/volgold)); /* loop */ do panacea = 0 to maxpanacea; do ichor = 0 to maxichor; do gold = 0 to maxgold; output; end; end; end; run; *** Code chunk number 27 ***; data two; set one; totalweight = wtpanacea*panacea + wtichor*ichor + wtgold*gold; totalvolume = volpanacea*panacea + volichor*ichor + volgold*gold; if (totalweight le maxwt) and (totalvolume le maxvol); vals = valpanacea*panacea + valichor*ichor + valgold*gold; run; *** Code chunk number 28 ***; proc sort data=two; by descending vals; run; proc print data=two (obs=5) noobs; var panacea ichor gold vals totalweight; run;