SAS PROGRAMMING CS 2331
Popular in Course
Popular in ComputerScienence
This 0 page Class Notes was uploaded by Ms. Bridie Kohler on Sunday November 1, 2015. The Class Notes belongs to CS 2331 at Oklahoma State University taught by Staff in Fall. Since its upload, it has received 15 views. For similar materials see /class/232839/cs-2331-oklahoma-state-university in ComputerScienence at Oklahoma State University.
Reviews for SAS PROGRAMMING
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 11/01/15
PLOT PROCEDURES PROC PLOT describes the relationship between columns by plotting their values This chapter explains how to make a plot and how to control the appearance of your plots Plotting Data Plotting data enables you to graphically illustrate the relationship between columns The PLOT procedure reads the values of sets of columns and marks the intersection of each pair of values as a point on the plot To produce a simple plot of one set of columns enter a PROC PLOT statement followed by a PLOT statement The PROC PLOT instructs SAS to produce a plot using speci ed data PLOT statements specify the columns you want plotted The PLOT begins with the keyword PLOT and is followed by the names of the columns you want plotted on the vertical and the horizontal axes joined by an asterisk You just learned about using label statements when you printed out something They make a column name more meaningful This is certainly useful with plots If you define the labels at the beginning of the program every time you refer to that data set the labels are available When you use the proc plot you do not need to use the label statement in order to have them appear in the output An example follows data stwt infile 39ahealthdat39 input name 623 team 2530 stwgt 3234 endwgt 3638 sex 40 age 4243 height 4546 loss stwgt endwgt label name Name team Team Name stwgt Starting Weight endwgt Ending Weight sex Sex age Age height Height loss Loss proc plot datastwt plot heightstwgt run PROC PLOT automatically selects the plotting symbol A to represent one occurrence at each point If two occurrences coincide at a point the plotting symbol B is used If three were at a point C would be used etc PLOT 0F HEIGHT BY STARTING WIGHT P39Iot of heightstwgt Legend A 1 obs B 2 obs etc nza m as so gt 611 A A ffAfffffffffffAfffffffffffAfffffffffffifffffffffffifffffffffffAfffffffffffAfffffffffffkff 125 150 175 200 225 250 275 300 Starting weight PROC PLOT also selects ranges for both axes places tick marks at reasonably spaced intervals and prints the legend that names the columns and explains the symbols Controlling the Appearance of Plots Although PROC PLOT determines many plot characteristics by default such as the plotting symbol and the tick marks you can control the appearance of them by specifying your own These enhance the plots and increase their effectiveness Specifying Plotting Symbols PROC PLOT uses letters of the alphabet as default plotting symbols you can specify your own To do this you enter a PLOT statement containing the vertical and horizontal column names followed by an equal sign and the character you select surrounded by single quotes An example of a plot using a symbol follows data stwt infile 39ahealthdat39 input name 623 team 2530 stwgt 3234 endwgt 3638 sex 40 age 4243 height 4546 loss stwgt endwgt label name Member Name team Team Name stwgt Starting Weight endwgt Ending Weight sex SeX age Age height Height loss Loss Proc plot datastwt plot heightendwgt title PLOT OF HEIGHT BY ENDING WEIGHT run Note When you specify a plotting symbol PROC PLOT uses that symbol for all points on the plot regardless of how many points coincide If points coincide a message appears at the bottom of the plot telling you how many rows are hidden Notice that SAS handles the missing values by putting a note at the bottom of the graph informing you how many rows has a missing value Also see the use of the label statements in the plots The endwgt has the label of Ending Weight which is easier for others to understand When you make plots or charts one of the purposes is to make it easier for others to understand the information through a Visual picture 50 PLOT 0F HEIGHT B YENDING WEIGHT P39Iot of heightendwgt Symbo39l used is 3939 nza m as 9 ea 611 ffffffffff ffffffffff ffffffffff ffffffffff ffffffffff ffffffffff ffffffffff ffffffffff f 100 125 150 175 200 225 250 275 300 Ending weight NOTE 1 obs had missing values 2 obs hidden De ning Tick Marks You can also control the location of tick marks on the horizontal axis by specifying your selection using the HAXIS option in the PLOT statement A corresponding VAXIS option controls tick marks on the vertical axis You specify your tick mark location in the PLOT statement by entering the column names followed by a slash the option name an equal sign and then the values you want to assign to the tick marks NOTE You can add many options after the slash You only need ONE slash To specify the tick marks on both axes enter HAXIS and VAXIS options separated by one or more blank spaces An example follows Proc plot datastwt plot heightstwgt3939 haxis100 to 300 by 20 vaxis 60 63 66 69 72 75 78 81 title quotSKINNY S HEALTH CLUB STARTING WEIGHT PLOTquot run 51 SIGNNY39S HEALTH CLUB STARTING WEIGHT PLOT P39Iot of heightstwgt Symbo39l used is 39339 751 s s s 3 H72 3 s s E 139 s 9 h s s s t 69 3 1 3 ss 1 s s 661 s s ss 3 s s s 631 3 ss ss 3 s 60 1 Sff fffffffAfffffffkffffffffffffffAffffffffffffffAfffffffAfffffffffffffffkfffffff f 100 120 140 160 180 200 220 240 260 280 300 Starting weight NOTE 1 obs hidden Creating Multiple Plots You can create multiple plots in a variety of formats Creating Multiple Plots 0n Separate Pages You may produce multiple plots from the same data set by specifying additional sets of columns in the PLOT statement The following will produce two plots on separate pages Proc plot datastwt plot heightstwgt3939 heightendwgt39 39 run Two plots will appear on separate pages There is no output of this plot You may also superimpose multiple plots on one set of axes by using the OVERLAY option An example follows Proc plot datastwt plot heightstwgt3939 heightendwgt3939 overlay 52 title TWO PLOTS OVERLAYED ON THE SAME AXES run TWOPLOTSOVERLAIED ON THE SAIWEAXFS P39Iot of heightstwgt Symbo39l used is 399639 P10 of heightendwgt Symbo39l used is 3939 77 39 r 96 76 39 r 96 7s 39 r 96 74 1 73 96 96 96 72 96 96 96 71 39 r 96 H y e 70 96 96 96 69 39 r 96 t 68 96 96 96 67 96 96 66 96 96 65 96 96 96 96 64 39 96 r 96 63 96 96 96 62 96 96 61 1 9s 9s AffffffffffAffffffffff ffffffffffAffffffffffAffffffffffAffffffffff fffffffffffffffffffff 100 125 150 175 200 225 250 275 300 Starting weight NOTE 1 obs had missing values 4 obs hidden Creating Multiple Plots 0n the Same Page PROC PLOT provides two options that produce two or more plots on the same page the VPERCENT and the HPERCENT option The VPERCENT option can produce multiple plots on a page with one plot beneath the other on a page The HPERCENT places one or more plots side by side on a page The numeric value assigned to the option speci es the percentage of the vertical or horizontal dimension of the page to assign to the plot To produce two plots on the same page with one beneath the other use the following proc plot vpercent50 plot height stwgt heightendwgt title USE OF THE VERTICAL PERCENT FOR PLOTS run USE OF THE VERTICAL PERCENT F OR PLOTS 53 P39Iot of heightstwgt Legend A 1 obs B 2 obs etc 80 A H A A e A A A 139 A A A A g 70 A A A A h AA AA A t AA B A A A A B A A A A A A 60 A SH fffffffffff fffffffffff fffffffffff fffffffffff fffffffffff fffffffffff fffffffffff ff 125 150 175 200 225 250 275 300 Starting weight P39Iot of heightendwgt Legend A 1 obs B 2 obs etc 80 A A H A A e B 1 A A A A g 70 A A A h A A A A A t AAB A A A A AA A A AA A A 60 5 ffffffffff ffffffffff ffffffffff ffffffffff ffffffffff ffffffffff ffffffffff ffffffffff f 100 125 150 175 200 225 250 275 300 Ending weight NOTE 1 obs had missing values You can also produce side by side plots An example is proc plot hpercent50 plot height stwgt heightendwgt title USE OF THE HORIZONTAL PERCENT FOR PLOTS run 54 USE OF HORIZONTAL PERCENT FOR PLOTS 10 of heightstwgt A1 52 etc 10 of heigh endwgt A1 B2 etc 77 39 A 77 39 A 76 39 A 76 39 A 75 39 A 75 39 A 74 39 74 39 73 39 A AA 73 39 AA 72 39 A A A 72 39 A A A 71 39 A 71 39 A H l H 1 e 70 A AA e 70 A A A 69 A 69 A t 68 A A A t 68 A A A 67 39 A A 67 39 A A 66 39 A A 66 39 A A 65 39 A s A A 65 39 AB A A 64 39 A A 64 39 A A 63 39 A AA 63 39 A AA 62 A A 62 1 AA 611 A A 61 1 A A gffffffffffffffffgngfffffffffffffffg g gffffffffffffffffgngfffffffffffffffg g Starting weight Ending weight NOTE 1 obs had missing va39lues You can also use both by using the VPERCENT and HPERCENT at the same time proc plot hpercent50 Vpercent50 plot heightstwgt heightendwgt agestwgt ageendwgt title PLOTS USING HPERCENT AND VPERCENT run 55 PLOTS USING HPERCENT AND WERCENT P39Iot orf heightstwgt A1 52 etc 80 A H A A e A A 139 A A A A g 70 A A AA h AA AAA t 5 5A A A A 5A A A AA A 60 5 ffffffffffffffffff ffffffffffffffffff f 100 200 300 Starting weight P39Iot of agestwgt A1 52 etc 60 A A A 5 A A A A A A A A A g AA A A e 40 A A A A A AA A A A A AA A A A A A 20 A A 5 ffffffffffffffffff ffffffffffffffffff f 100 200 300 Starting weight Using the BY statement with Plots NOTE NOTE P39Iot of heightendwgt A1 52 etc A A A AA AA A A A A A A AA A AA 55 A A A AAAA A AA A A ffffffffffffffffffAffffffffffffffffff f 100 200 300 Ending weight 1 obs had missing values P39Iot of ageendwgt A1 52 etc 39 A A 5 1 A A y A A 5 5 A A A A A A A A B B A A AA 0 1 A 5AffffffffffffffffffAfffffffffffffffffff 1 200 300 00 Ending weight 1 obs had missing values You can sort on some particular column and make separate plots for each column in the sort An example would be proc sort proc plot by sex plot heightstwgt by sex title USE OF BY STATEMENTS FOR PLOTS run 56 nza m nza m USE OF BYSTATEIMENTSFOR PLOTS SexF P39Iot of heightstwgt Legend A 1 obs B 2 obs etc A l A A l A l A l A l A l A l A A l A B A l A A l A A l A A l A A ff fffffffffff fffffffffff fffffffffff fffffffffff fffffffffff fffffffffff fffffffffff ff 125 150 175 200 225 250 275 300 Starting weight USE OFBYSTATEIWNTSFOR PLOTS SexM P39Iot of heightstwgt Legend A 1 obs B 2 obs etc 1 A fffffffffffffAffffffffffffffffffffffffffffffffffffffffffffAffffffffffffffffffffffff 140 160 180 200 220 240 260 280 Starting weight 57 There will be two plots The first one will have only the females on it and the second one will have only the males on it These will still use the quotAquot quotBquot etc symbols Using the Symbols of the Column in the Plot You can also display the data for males and females on a single plot Instead of using the usual plotting symbols of ABC etc you can use the quotMquot and quotFquot symbols This only works when there are a few choices listed in the column values Examples are M and F for male and female Another for class could be 1 2 3 4 The program for this is nza m NOTE 1 obs hidden plot heightstw gtsex title PLOT OF HEIGHT BY STARTING WEIGHT title2 LISTED BY SEX OF M AND F PLOT 0F HEIGHT BY STARTING WIGHT LISTEDBYSEXOFMANDF P39Iot of heightstwgt symbol is value of sex F ff fffffffffff fffffffffff fffffffffff fffffffffff fffffffffff fffffffffff fffffffffff H 150 175 200 225 250 275 300 Starting weight 58 Review of Features Used with PROC PLOT These are the features that can be used with PROC PLOT PROC PLOT DataSAS data set VPERCENT HPERCENT Vpercent produce multiple plots on a page Hpercent produces multiple plots across the page PLOT VerticalColumn HorizontalColumn Character options Options include HAXIS tick marks on horizontal aXis VAXIS tick marks on vertical aXis OVERLAY overlays two or more plots on a single pair of axes PLOT VerticalColumn HorizontalColumn Column name BY Column LABEL column name teXt 59
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'