This action might not be possible to undo. Are you sure you want to continue?

# An Introduction to SAS SAS is the program and programming language that will be used for nearly all analyses

in our course this semester. These days nearly all statistical packages have the familiar windows based format with drop down menus that allow the user to quickly select the operations of choice. SAS seems to have bucked this trend, for although SAS has the classic windows form, it does not provide you with simple drop down menu choices. Instead, SAS requires that you “program” you analytic choices. This requires skill at programming, knowledge of the programming language and knowledge of how SAS operates. This short tutorial will provide you with a working introduction to SAS. It is in no way meant to be a comprehensive course on the subject. Instead, this tutorial is meant to be a starting point from which you may extend your understanding of SAS when the need arises.

The SAS interface is shown in the following screen shot:

There are several items of importance shown in the screen shot. First there are the usual main menu items, such as File, Edit, etc. I seldom use anything but the File and Edit menu items. In the File menu there are the typical Open, Close, Save, Print, etc. items, while in the Edit menu there is Copy, Paste, Replace, etc. For the most part these are all I use. The Help menu may or may not be fully functional. In the past this would be the approach to opening the SAS online documentation. On my current PC I must open the online documentation by going to the START icon, going to All Programs, finding SAS in the list of programs and among the SAS software items is the Documentation.

1

RUN. A Short Course on SAS Commands Before any data can be analyzed. There are essentially two methods of SAS data file creation: either the dtat is entered in the program code stream or the data is entered from an external data file. All warnings and errors will show up in the Log. INPUT variable_1 variable_2 @@@ variable_n. I typically close the Explorer window in the left panel. You can also tile these windows. the most important of which are the Submit. For this reason it is a good idea to look at the Log for problems. INPUT.g. 3rd and 2nd from the last items. which reports on operation of the SAS. . The other window of importance is the Output window.”. CARDS. data row n . SAS statement_n. . INFILE and CARDS statements. Therefore. Clear All and Break (4th.. This is performed in a DATA step. respectively). A SAS data file persists only while the session is running (from the time you load SAS until you terminate the program). . Log and Editor). to perform any analyses using SAS you must first create a SAS data file. Output. Data Input SAS code manipulates SAS data files. SAS statement_2. . Some of these statements have several options available. This is where all of the results from the submitted program will reside. SAS statement_1. where all SAS code goes and the Log. whether it is to compute the statistics for an analysis of variance or to add two numbers together. There are several SAS statements required to create a SAS data file. You can bring any of the three windows into focus by clicking on the appropriate button at the bottom of the screen (e. This is very useful if you have made a coding mistake that results in an infinite loop or when a SAS procedure is running too long due to model complexity. These include the DATA. all programs will originate from the Editor window. If you place the cursor over these icons you will get a brief description of each. The general form of a data step with the data entered in the program stream is: DATA filename. The Clear All button simply clears all text in the Editor window and the Break button will stop SAS processing a set of code. All SAS statements end with a semicolon “. you must make the data available to SAS. data row 1 data row 2 .On the Command bar (second bar from the top) are a series of icons. The two of importance that are shown are the Editor. 2 . There are typically three windows of importance to SAS programs (only two of the important one are shown in the screen shot. . The Submit button submits the set of SAS code that is located in Editor window.

. SAS statement_2. since the example data sets are relatively small. 3 . it is usually easier to initially save your data in a spreadsheet program. INPUT variable_1 variable_2 @@@ variable_n. SAS statement_n. . . However. For all programs developed over the next several pages only the first approach will be used.The general form of a data step with the data entered from an external file is: DATA filename. SAS statement_1. RUN. such as Excel. INFILE “path and filename” options. and then access the data from the file by using the INFILE statement.

The default data type is numeric. use a period. There are several options available for the INPUT statement. These SAS Statements appear in the data step following the INPUT statement. If data are missing. if Y ^= Z then X = 2. variable_2. X = Y + Z. SAS Statements in the data step can be used to manipulate data or create new variables. or DATALINES. INFILE “path and file name” options. CARDS. variable_n. Arithmetic Operators operator ** * / + function raise to a power multiplication division addition subtraction example X = Y**Z. X = Y*Z. The firstobs option indicates from which row of the data file to start reading.Z. The path and file name are specified in quotes. if Y > Z then X = 2. but only a couple will be discussed. X = Y/Z. Initializes the data step and assigns the “filename” to the SAS data file. 4 . @@@. but after the definition of the variables. variable_n are to be created using in-stream data entry.The SAS statements in the DATA step: DATA filename. Comparison Operators operator = or EQ ^= or NE > or GT < or LT >= or GE <= or LE function equal to not equal to greater than less than greater than or equal to less than or equal to example if Y = Z then X = 2. These SAS statements can be arithmetic. if Y <= Z then X = 2. INPUT variable_1. Character data must be followed by a $. variable_2. Data will be read from an external file. X = Y . Indicates that the data are to be entered in-stream and directly follow the CARDS statement. @@@. The “character” in the dlm option is typically a comma since this is the separator between columns of a comma separated value file (MS Excel data type). if Y >= Z then X = 2. Data may be numeric or character. if Y< Z then X = 2. Two main options are of use here: dlm = “character” and firstobs = n. The @@ character at the end of an INPUT statement allows for data to be read in multiple complete sets from the same data line. Here n is an integer. logical or functional in nature and are located within the data step. Variables variable_1.

Logical Operators operator & or AND | or OR ^ or NOT function intersection of two logicals union of two logicals complement example if Y = Z AND X = 2 then W = X. LOG is the function for the natural logarithm and Y is the argument. if NOT (Y = 2) then W = X. SAS Functions SAS function can be applied to variables or constants. if Y = Z OR X = 2 then W = X. A Survey of SAS Functions function ABS SQRT ROUND LOG LOG10 ARCOS ARSIN ATAN COS SIN TAN POISSON PROBBNML PROBCHI PROBF PROBNORM PROBT CINV FINV PROBIT TINV definition Absolute value Square root Rounds to the nearest roundoff unit Natural logarithm Logarithm base 10 Arc-cosine Arc-sine Arc-tangent Cosine Sine Tangent Poisson probability distribution function (cumulative probability) Binomial probability distribution function (cumulative probability) Chi-square probability distribution function (cumulative probability) F probability distribution function (cumulative probability) Standard normal probability distribution function (cumulative probability) T probability distribution function (cumulative probability) Inverse of the chi-square distribution function (quantile) Inverse of the F distribution function (quantile) Inverse of the normal distribution function (quantile) Inverse of the T distribution function (quantile) 5 . The functional form would be: X = LOG(Y). Here. The argument can be either a defined variable or a constant. For example. suppose you wanted to create a new variable X that was the natural logarithm of the variable Y.

too many to discuss here. SAS procedures are essentially functions. The procedures of interest to the analysis of variance include: PROC GLM PROC ANOVA PROC MIXED PROC UNIVARIATE PROC PLOT PROC SORT PROC TTEST PROC REG general linear models procedure for analysis of variance and regression analysis of variance procedure mixed model analysis of variance procedure univariate statistics and tests for normality X. “new” in this case. Y and Z. reading from left to right. comparison operators. PROC GLM. However.SAS Data File Creation Using In-Stream Data Entry: In the following example. it is time to create a SAS data set and use a procedure. 10 Kim Forester 15 Jim Green 25 Peter Zanis . while the procedures documentation can be found in the SAS/STAT pages (near the bottom of the list). logical operators. SAS functions and SAS procedures are discussed in detail within the online documentation. cards. Some of the basic statistical procedures supplied by SAS include PROC UNIVARIATE. SAS procedures are far more complex and produce and array of output. Y scatter plot procedure sort data in ascending or descending order perform both an independent two sample t-test and a paired t-test regression analysis procedure The use of arithmetic operators. SAS reads data line by line. input X Y $ Z $. There are many more SAS PROCs. they are needed to see the results of the data step. You should explore these pages for your own benefit. For the Print procedure the only option used is specification of the data set to use. while Y and Z will be character variables. unlike the functions just described. logical operators. The arithmetic operators.” and “run. 6 . The data set “new” is printed (results will appear in the Output window) using the Print procedure. a SAS data set named new will be created with variables X. All SAS procedure call begin with the key work PROC. The “Proc Print data = new. Each procedure will have many possible options or statements. run.SAS Procedures The effectiveness of SAS as a statistical software package lies in the union of the ability to manipulate data in the data step and then send the data to a procedure for further analysis. Now that you have some understanding of the lay-out of SAS. Example .” statements are not needed for the data step. X will be numeric. PROC REG. PROC PLOT PROC ANOVA PROC MIXED and PROC LOGISTIC. SAS functions can be found in the Base SAS pages. data new. Proc Print data = new. comparison operators. To invoke a procedure you simply use the term “proc” followed by the procedure name.

Entering the example SAS code into the SAS Editor window and clicking on the Submit button produces the following screen shot: 7 .

Other options for this statement are linesize = n and pagesize = n. He places eleven (11) type 1 traps and eight (8) type 2 traps out during the night. title "Comparison of Two Types of Moth Traps". cards. including Proc ttest for the comparison of two means from independent samples are: options pageno = 1.) (Tells Proc ttest which variable to use to determine the two treatments or populations) (Tells Proc ttest which variable is the response) 8 var Moths. var Moths. run. title2 "Analysis Using an Independent Two-Sample T-test". Are the title and subtitle printed on each page of the output following their definition (the subtitle will not be printed for the above program until after the Proc Print has been run). proc ttest data = moths. The data collected from this study are presented below. The components.Comparison of Two Means for Independent and Dependent Samples Using SAS Proc TTEST Example . for the program. he counts the number of moths caught in each trap. which are used to set the number of characters across a page and the number of lines on a page.Independent Samples An entomologist is interested in the effectiveness of two different types of moth traps. In this instance the “pageno = 1" option forces SAS to number its pages starting with 1. run. . title2 "Analysis Using an Independent Two-Sample T-test". The entomologist would like to know if there is a difference between the catch rate of the two traps. data moths. Later. class Trap_Type. If this were left off. TRAP 1 TRAP 2 41 34 33 36 40 25 31 37 34 30 38 52 57 62 55 64 57 56 55 SAS Code using Proc ttest options pageno = 1. proc ttest data = moths. class Trap_Type. The options statement can go anywhere in SAS and is used to control some aspects of the output. title "Comparison of Two Types of Moth Traps". SAS would have begun numbering from where it left off. 1 41 1 34 1 33 1 36 1 40 1 25 1 31 1 37 1 34 1 30 1 38 2 52 2 57 2 62 2 55 2 64 2 57 2 56 2 55 . input Trap_Type Moths @@. with explanation. (Invokes Proc ttest and tells SAS to use the “moths” data set. proc print data = moths. run.

1 5. the two treatments were administered for four weeks each in random order to 10 patients.9 12. The components.1 3. paired placebo*deanol.7 12.1 5. run.5 9.5 11. with explanation.0 8.6 6.2 12.0 5. Results from these treatments.4 ------------------------------------------------------------------------------------------------------------- SAS Code using Proc ttest: options pageno = 1.8 13. input placebo deanol.4 5. of Proc ttest for the comparison of two means from paired samples are: proc ttest data = drug.4 12.2 12.7 12. 12.8 9.Example .0 11.9 12. title2 "Analysis Using an Paired T-test".6 Placebo 9.2 12. In an experiment to see whether the drug deanol produced an effect over baseline scores of a placebo treatment.5 13.) (Describes the paired responses for comparison .5 7.2 12.4 5.Dependent Samples Tardive dyskinesia denotes a syndrome comprising a variety of abnormal involuntary movements assumed to follow long-term use of antipsychotic drugs.1 9.2 13. datalines.) 9 .4 9. (Invokes Proc ttest and tells SAS to use the “drug” data set.6 12.2 12.0 9. proc ttest data = drug. run.5 7. data drug. as measured by total severity index (TSI) scores are: Patient 1 2 3 4 5 6 7 8 9 10 ------------------------------------------------------------------------------------------------------------Deanol 12.1 3. paired placebo*deanol.9 8.5 6.1 12. title "Comparison of Two Types of Treatments for Tardive Dyskinesia".6 13.4 .9 5.

In the above code you are using a function “ranuni(1)” which creates a uniform (0. data random. proc print data = random. labeled 1 to n. proc sort data = random. set random. Replicate = _n_. In this instance. the data set “random” is created by the statement “data random. These two sets are sorted based on the uniform random numbers and printed. follows directly from the printed treatments. but you must choose one. rv = ranuni(1). input treatments @@. by rv. The SAS code performing the random assignment of treatments to experimental units is data random. with exactly the same number of treatment values as there are observations for a given sample.. run. by starting a new DATA step.Randomization of Treatments to Experimental Units for a CRD using SAS For a completely randomized design the randomization of the treatments to a set experimental units is a fairly simple process. 2. You can re-open a data set. The Sort procedure sorts the declared data set (random) using the values in the variable “rv”. The seed can be any positive whole number. cards. The assignment of experimental units.”. 1. The 1 in parentheses is the “seed” to start the random number generation and is required. Next a set of uniform random numbers is created using the SAS uniform random number function (RANUNI). By default they are sorted in descending order. 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 . 1) random variable for each observation (total of 16).” and is populated by the existing data set “random” by using the statement “set random. You should look at the SAS Online documentation to learn more. run. by rv. Replicate = _n_. data random.g. or create a new data set from an existing data set. Options for the sort routine allow for other methods of sorting. etc.Example . set random. 10 . each with 5 observations (replicates). rv = ranuni(1). proc sort data = random. Example Suppose that an experiment which was to follow the protocol for a completely randomized design was to involve 4 treatments. This statement declares a new variable “Replicate” with indexed values created by the SAS variable “_n_”. First you must construct a variable which has entries corresponding to the treatment values (e.).

It is of interest to EPA that these laboratories produce equivalent results when asked to analyze water samples for possible contamination. run. model ddt = laboratory. In the above code. run. the response (DDT) is a function of the treatment (Laboratory). model ddt = laboratory. proc print data = epa. 1 1005 1 1015 1 1033 1 1028 1 1023 1 1043 2 995 2 1008 2 976 2 1014 2 1011 2 982 3 950 3 975 3 988 3 1015 3 1008 3 994 . run. class laboratory. run. 11 . The statistical design is a completely randomized design with a one-way treatment structure (Laboratories). title2 "Using a Completely Randomized Design". data epa. proc glm data = epa. The key elements of the analysis are: proc glm data = epa. This will produce the ANOVA table with the F-test and Pvalues. Any remaining variation goes to the residual error. Each water sample was constructed independent of the others and randomly assigned to a laboratory. The resulting data are given in the following table: Replicates Laboratory 1 2 3 1 1005 995 950 2 1015 1008 975 3 1033 976 988 4 1028 1014 1015 5 1023 1011 1008 6 1043 982 994 title "Analysis of EPA Laboratory Data".Analysis of a Completely Randomized Design with a One-Way Treatment Structure Using SAS The Environmental Protection Agency (EPA) utilizes the services of a number of analytic laboratories. The model statement relates the response (DDT) to the factor (Laboratory). In order to assess the quality of the analyses from these laboratories the EPA decided to send each of 3 laboratories a set of 6 samples that were known to have a DDT contamination level of 1000 ppm. title3 "With a One-Way Treatment Structure". The model for a CRD with a one-way treatment structure codes for a “grand mean” or model intercept and the treatment effects (Laboratory in the above example). In this case Laboratory is the factor. input laboratory ddt @@. Replicates are the source of random variation and appear in the residual error. The class statement tells Proc GLM which factors are in the ANOVA. class laboratory. cards. Proc GLM is the general linear models procedure which can be used to run ANOVA or regression analysis.

For now. Remember. However. there is a consequence in running the analysis in this manner. input laboratory ddt @@. For the simple models of a completely randomized design with a oneway treatment structure. proc print data = epa. 2. Proc Mixed uses the method of maximum likelihood (ML) to obtain the estimates of the model parameters. cards. In addition. If the response Y was recorded as DDT. Please recall that the model for the EPA data is based on a CRD with a one-way treatment structure. run. proc mixed data = epa. 5 and 6 within each laboratory). For this data set. the results from Proc GLM and Proc Mixed are identical. Later it will become apparent that these methods are not exactly the same. we will want to use Proc Mixed for more complicated designs because maximum likelihood estimation is more robust to violations of the assumptions and when missing observations occur. class laboratory. 2.Proc Mixed is another SAS procedure that will produce the test statistics and parameter estimates for ANOVA models. run. data epa. Proc Mixed can be used to model the variance structure when you have non-constant variance. However.µ is the effect of the ith treatment are independently and identically distributed normal random errors having mean 0 and common variance σ2. 4. run. . Explore this consequence by making the appropriate changes to the SAS code on this page. which included the replication for the model statement would be model DDT = Laboratory Sample (Laboratory). the model is of the following structure: Yij = µ + τi + ε(i)j Definitions and Assumptions: Yij µ τi ε(i)j the measured response for the ith treatment and jth observation the grand mean = µi . In fact. title3 "With a One-Way Treatment Structure". in addition to the primary factor (Laboratory). 3. title2 "Using a Completely Randomized Design". model ddt = laboratory. 12 . 1 1005 1 1015 1 1033 1 1028 1 1023 1 1043 2 995 2 1008 2 976 2 1014 2 1011 2 982 3 950 3 975 3 988 3 1015 3 1008 3 994 . you can label the replicates as a factor. the treatments were recorded as Laboratory (1. 3) and the Replication was recorded as Sample (1. the SAS Proc Mixed code for the EPA data should be: title "Analysis of EPA Laboratory Data". then the SAS code.

19). As an example. If you actually knew the true means for the different treatments you wouldn’t even need to run the experiment. 2013 The POWER Procedure Two-sample t Test for Mean Difference Fixed Scenario Elements Distribution Method Mean Difference Standard Deviation Group 1 Weight Group 2 Weight Nominal Power Number of Sides Null Difference Alpha Normal Exact 10 4.05 Computed N Total Actual Power 0.Computing Power of the Test for the Independent Two Sample t-Test SAS Proc Power can be used to determine power or sample size for designed experiments. By meaningful I mean values for the means that imply the minimum detectable difference that is important.38 (variance is 19. then the SAS Proc Power code for determining sample size for a power of 0.8 is as follows: proc power.. then you would also have a value of the anticipated variance. This is because you must define the relative values of the means that are expected if the experiment were to be conducted and you must define the true value of the variance. If this were the case. so you must come up with values that you think represent a meaningful set of values.8 2 0 0. run. If we believe that a meaningful difference in the true means is 10 and the standard deviation was 4. however. Proc Power is quite easy to use.38 1 2 0. or from the literature. You might deduce these values from a pilot study. Results Comparison of Two Types of Moth Traps 1 Analysis Using an Independent Two-Sample T-test 08:46 Friday. twosamplemeans meandiff= 10 stdev=4. First. there are a couple of concepts that you must understand before using the procedure. consider the moth trap problem. May 10. Of course you don’t know the values of the means. you must understand that the results of the power calculations are only a guideline.918 N Total 12 13 .8 ntotal=.38 groupweights=(1 2) power=0.

The data from this experiment. Levene’s test can be constructed using a little creative programming. Assessing constant variance can be performed by plotting the residuals against either the treatment levels or the treatment means. consider the following experiment and data: Example: Seventy-eight (78) male workers were assigned at random to six different groups so that 13 were in each group. some (10) individuals withdrew from the experiment before their training was complete. Residuals are constructed as follows: . the pulse rate was measured for 20 seconds. Both of these approaches are implemented by SAS Proc Univariate. As an example of these methods. Here. Unfortunately. Assessing the assumption of normality can be performed by constructing a normal probability plot or running formal test of hypothesis. In addition. Yit represents the response for the jth observation on the ith treatment and the i treatment.Assessing Model Assumptions Using SAS Residuals are key elements for assessing model assumptions. along with some summary statistics are reproduced in the following table: Group 1 27 31 26 32 39 37 38 39 30 28 27 27 34 2 29 28 37 24 35 40 40 31 30 25 29 25 3 34 36 34 41 30 44 44 32 32 31 4 34 34 43 44 40 47 34 31 45 28 5 28 28 26 35 31 30 34 34 26 20 41 21 6 28 26 29 25 35 34 37 28 21 28 26 th the estimated mean for 14 . After training in a specific task. such as the Anderson-Darling test.

run. Also included in the program code are the methods of using Proc Univariate to extract the normal probability plot and the Anderson-Darling test for normality.37). title2 "Assessing the Assumption of Normal Residuals". run. title2 "Levenes Test for Equality of Variances . title2 "Analysis of Variance for Raw Data". if group = 1 then z = abs(pulse .28). proc print data = task. options pageno = 1. run. if group = 4 then z = abs(pulse . data task.34). a second Proc GLM analysis is performed to produce Levene’s test for equality of the variances. output out = new r = residuals. run. plot residuals*group. model z = group.29). run. proc glm data = task. cards. set task. title2 "Residual Plot for the Raw Data". Prior to this last Proc GLM run. title3 "Using the Normal Probability Plot and the Wilk's-Shapiro Test".29. 15 .5). if group = 3 then z = abs(pulse . class group. class group. 27 1 29 2 34 3 34 4 28 5 28 6 31 1 28 2 36 3 34 4 28 5 26 6 26 1 37 2 34 3 43 4 26 5 29 6 32 1 24 2 41 3 44 4 35 5 25 6 39 1 35 2 30 3 40 4 31 5 35 6 37 1 40 2 44 3 47 4 30 5 34 6 38 1 40 2 44 3 34 4 34 5 37 6 39 1 31 2 32 3 31 4 34 5 28 6 30 1 30 2 32 3 45 4 26 5 21 6 28 1 25 2 31 3 28 4 20 5 28 6 27 1 29 2 41 5 26 6 27 1 25 2 21 5 34 1 . the data set “Task” is re-opened and a new variable “z” is constructed by computing the absolute value of the median based residuals and the variable “z” is used to construct Levene’s test. Lastly. if group = 5 then z = abs(pulse . proc plot data = new. title "Analysis of Pulse Rate for 6 Treatment Groups". proc univariate data = new normal plot.31). var residuals. input pulse group @@. if group = 2 then z = abs(pulse . model pulse = group. data task.The SAS code for running the ANOVA and extracting the residuals using Proc GLM are provided below. proc glm data = task. title3 "Analysis of Variance for Median Based Residuals". run. if group = 6 then z = abs(pulse .Raw Data".

cards. model pulse = group.Using Proc Mixed the variance structure can be assessed with the following code: options pageno = 1. input pulse group replicate @@. From this code. 28 26 29 25 35 34 37 28 21 28 6 6 6 6 6 6 6 6 6 6 1 2 3 4 5 6 7 8 9 10 The repeated statement indicates that the response is measured repeatedly for the defined subject. In this case the subject statement tells Proc Mixed that “replicate” is measured multiple times for each “group”. title "Analysis of Pulse Rate for 6 Treatment Groups". proc mixed data = task. the type = un(1) statement indicates that the variances are allowed to differ among groups. 16 . class group replicate. proc print data = task. data task. run. repeated / type = un(1) subject = replicate. In addition. 27 1 1 29 2 1 34 3 1 34 4 1 28 5 1 31 1 2 28 2 2 36 3 2 34 4 2 28 5 2 26 1 3 37 2 3 34 3 3 43 4 3 26 5 3 32 1 4 24 2 4 41 3 4 44 4 4 35 5 4 39 1 5 35 2 5 30 3 5 40 4 5 31 5 5 37 1 6 40 2 6 44 3 6 47 4 6 30 5 6 38 1 7 40 2 7 44 3 7 34 4 7 34 5 7 39 1 8 31 2 8 32 3 8 31 4 8 34 5 8 30 1 9 30 2 9 32 3 9 45 4 9 26 5 9 28 1 10 25 2 10 31 3 10 28 4 10 20 5 10 27 1 11 29 2 11 41 5 11 26 6 11 27 1 12 25 2 12 21 5 12 34 1 13 . Proc Mixed will create a test for equality of variances. run.

model ddt = laboratory. 1 -1. There are several different analytic tools available for this type of analysis. proc glm data = epa. The effect indicates to SAS the name of the effect or treatment factor that appears in the model (e.g. 1 1005 1 1015 1 1033 1 1028 1 1023 1 1043 2 995 2 1008 2 976 2 1014 2 1011 2 982 3 950 3 975 3 988 3 1015 3 1008 3 994 . Contrasts are of the following basic form: where and at least one ci … 0. This could be accomplished by adding the following contrast statements to the above code: contrast "Lab 1 vs. but the most basic is contrast of means. It might also be of interest to compare the first laboratory with the third and the second laboratory with the third. The full SAS code for this analysis is: title "Analysis of EPA Laboratory Data". Implementing contrasts using SAS Proc GLM is a relatively straightforward process. “mean 1 vs. laboratory). run.. 17 . A SAS Proc GLM contrast statement has the following form: contrast “label” effect values. data epa. cards. suppose that a person was interested in comparing the mean for the first laboratory with the mean for the second laboratory. input laboratory ddt @@. Lab 2" laboratory 1 -1 0. title2 "Using a Completely Randomized Design". mean 2").g. run. this signals the need for further analyses.g. Lab 3" laboratory 1 contrast "Lab 2 vs. Lab 3" laboratory 0 0 -1.. The values represent the coefficients of the contrasts (e. Using the EPA laboratory data as an example. The “label” appears in either single or double quotation marks and is a self specified label which identifies the contrast to the user (e. run. class laboratory. contrast "Lab 1 vs. The most common post ANOVA analysis is the comparison of means. A contrast is initiated with the contrast statement. the ci’s). title3 "With a One-Way Treatment Structure". proc print data = epa..Contrasts for Comparison of Means If the analysis of variance produces a significant F-statistic.

Lab 3" laboratory 0 1 -1. The full SAS code with the individual contrasts and the simultaneous contrasts would appear as follows: title "Analysis of EPA Laboratory Data". simultaneous contrasts can be created by replacing the semicolons of a set of contrasts with comma. suppose that it is of interest to simultaneously assess the contrast of the means for laboratory 1 and laboratory 3. 0 -1. Lab 3 and Lab 2 vs. run. data epa. cards. input laboratory ddt @@. and the contrast of the means for laboratory 2 and laboratory 3. model ddt = laboratory. For example. title3 "With a One-Way Treatment Structure". class laboratory. proc glm data = epa. title2 "Using a Completely Randomized Design". Lab 3" laboratory 1 laboratory 0 run. run. Lab 3" laboratory 1 0 -1. contrast "Lab 1 vs. which must have a semicolon.Simultaneous Inference for Two or More Contrasts It is also sometimes of interest to assess two or more contrasts simultaneously. proc print data = epa. contrast "Lab 1 vs. contrast "Lab 2 vs. Remembering that all SAS statements end with a semicolon. 18 . contrast "Lab 1 vs. except for the last in the set. 1 -1. 1 1005 1 1015 1 1033 1 1028 1 1023 1 1043 2 995 2 1008 2 976 2 1014 2 1011 2 982 3 950 3 975 3 988 3 1015 3 1008 3 994 . Lab 2" laboratory 1 -1 0.