HANDOUT ON GRAPHICAL COMMANDS IN SAS ==================================== 9/15/06 We have seen in class that it is desirable to display data using scatterplots, histograms, boxplots, and QQplots. Here are the basic commands needed to produce all of these. GOPTIONS HSIZE=7 VSIZE=7; options linesize = 70 nodate; libname home "."; data pima ; set home.pima; (I) Basic, low-quality scatterplot proc plot data=pima (obs=50); title "Low quality scatterplot, 50 Pima obs"; PLOT diastolic*bmi ; run; (II) Higher-quality scatterplot proc gplot data=pima ; title "Higher quality scatterplot, all Pima obs"; PLOT diastolic*bmi ; run; * To vary the plotting character, need "SYMBOL" declaration ; SYMBOL V="s" COLOR=BLACK; proc gplot data=pima ; title "Higher quality scatterplot, all Pima obs"; PLOT diastolic*bmi=1 ; run; * Most choices of SYMBOL are not allowed, and character reverts to the default "+" ; NOTE: we will in later exhibits and handouts discuss how to overplot lines onto scatterplots and (density) curves onto histograms. (III) Crude Histogram, BoxPlot and QQplot done together Proc Univariate data=pima plot; title "Basic Histogram & BoxPlot & QQplot"; var bmi; run; * Next comes one at a time ; Proc Univariate data=pima noprint; title "Histogram Alone"; HISTOGRAM BMI / MIDPOINTs = 0 to 60 by 10 normal ; INSET mean="Mean" (5.2) STD = "StdDev" (5.2) height=2.5; QUIT; RUN; proc chart ; title "Crude BMI Histogram Chart "; vbar bmi ; run; Proc Univariate data=pima noprint; title "QQplot Alone"; QQplot BMI ; RUN; (IV) Better Histogram proc gchart data = pima ; title "Better Gchart-based Histogram, BMI"; vbar BMI / type = pct; run; * This picture is really very nice : #### HERE IS ANOTHER, MAYBE MORE EFFECTIVE WAY TO SAVE PICTURES LIKE THIS ONE AND INTEGRATE THEM INTO YOUR EDITED HOMEWORK OR PROJECT SUBMISSIONS Step (1) Create your graph, eg the one above. (2) From the Graphical window, choose "Export as Image" from the file menu, and save the file as a bit-map (.bmp) image, naming it something like Outhist.bmp. (3) sftp the file Outhist.bmp back to your host computer if necessary. (4) Within a MS Word document, go to Insert Picture Fom File and find your file "Outhist.bmp". It will appear, with very good resolution, in your Word document. ######### ; (V) Boxplots by Group. proc sort data=pima out=pimagps; by diab; proc univariate data=pimagps plot; by diab; var bmi; title "Boxplots by Diab Group of BMI"; run; * Produces lots of output for each of the DIAB groups, but last page is a side-by-side boxplot of the two groups; Boxplots by Diab Group of BMI 1907 The UNIVARIATE Procedure Variable: bmi Schematic Plots | 80 + | | | * 60 + 0 | 0 0 | 0 0 | | | 40 + | +-----+ | +-----+ *--+--* | *--+--* +-----+ | +-----+ | 20 + | | | | 0 + 0 * ------------+-----------+----------- Diab 0 1 (VI) Empirical Distribution Function symbol V="s" color = black; symbol2 V=NONE I=JOIN Line=1; proc means data=pima mean std; var bmi; run; * get mean=31.993, std=7.884; proc sort data=pima out=pimsrt; by bmi; data pimsrt (keep = bmi bmrank bmnorm bmquant); set pimsrt; bmrank = _N_ /768; bmnorm = probnorm((bmi-31.993)/7.884); bmquant = probit(_N_/769); proc gplot data=pimsrt; title "Empirical Dist Fcn plot"; plot bmrank * bmi = 1 bmnorm * bmi = 2 / OVERLAY; run; QUIT; *# This plot overlays the empirical distribution (plotted points) with a plotted line, the normal distrbution function with the same mean and variance as the data. Finally, we generate a plot more closely related to the QQ ; proc gplot ; title "QQish plot"; plot bmi * bmquant; run;