The script is a series of statistical analysis examples. For each example, a dataset is first created via a DATA step with internal data (CARDS). Then, visualization procedures like PROC BOXPLOT and PROC SGPLOT are used to explore relationships between variables. The core of the analysis relies on PROC GLM (General Linear Models), which is used to perform: 1) An ANOVA to test the effect of a classification variable on a response variable. 2) An ANCOVA to do the same by adjusting the effect for a continuous variable (covariate). Least squares means (LSMEANS) are calculated to compare groups. This process is repeated for several datasets named medicine, data1, edu, na, and sale.
Data Analysis
Type : CREATION_INTERNE
All datasets (medicine, data1, edu, na, sale) are created and populated directly within the script using DATA steps and the CARDS/DATALINES statement. No external data is required.
1 Code Block
DATA STEP Data
Explanation : Creation of the 'medicine' table. The ' @@' option in the INPUT statement tells SAS to read multiple observations from the same data line.
Explanation : Analysis of Variance (ANOVA). This block tests whether the mean of the response variable 'y' significantly differs between groups defined by 'trt'. LSMEANS with TDIFF compares the means of each pair of groups.
Copied!
PROC GLM data=medicine ;
CLASS trt;
MODEL y=trt /SOLUTION;
LSMEANS trt/TDIFF;
RUN;
1
PROC GLMDATA=medicine ;
2
CLASS trt;
3
MODEL y=trt /SOLUTION;
4
LSMEANS trt/TDIFF;
5
RUN;
6 Code Block
PROC GLM
Explanation : Analysis of Covariance (ANCOVA). This model tests differences in 'y' between 'trt' groups while controlling for the effect of the continuous covariate 'x'.
Copied!
PROC GLM data=medicine ;
CLASS trt;
MODEL y=trt x /SOLUTION;
LSMEANS trt/TDIFF;
RUN;
1
PROC GLMDATA=medicine ;
2
CLASS trt;
3
MODEL y=trt x /SOLUTION;
4
LSMEANS trt/TDIFF;
5
RUN;
7 Code Block
DATA STEP Data
Explanation : Creation of a second dataset 'data1' with a character treatment variable ('A', 'B') and two numeric variables.
Copied!
data data1;
input trt $ x y;
cards;
A 5 20
A 10 23
A 12 30
A 9 25
A 23 34
A 21 40
A 14 27
A 18 38
A 6 24
A 13 31
B 7 19
B 12 26
B 27 33
B 24 35
B 18 30
B 22 31
B 26 34
B 21 28
B 14 23
B 9 22
;
RUN;
1
DATA data1;
2
INPUT trt $ x y;
3
CARDS;
4
A 520
5
A 1023
6
A 1230
7
A 925
8
A 2334
9
A 2140
10
A 1427
11
A 1838
12
A 624
13
A 1331
14
B 719
15
B 1226
16
B 2733
17
B 2435
18
B 1830
19
B 2231
20
B 2634
21
B 2128
22
B 1423
23
B 922
24
;
25
RUN;
8 Code Block
PROC GLM
Explanation : Execution of an Analysis of Covariance (ANCOVA) on the 'data1' dataset to evaluate the effect of 'trt' on 'y' by adjusting for 'x'.
Copied!
PROC GLM data=data1 ;
CLASS trt;
MODEL y=trt x /SOLUTION;
LSMEANS trt/TDIFF;
RUN;
1
PROC GLMDATA=data1 ;
2
CLASS trt;
3
MODEL y=trt x /SOLUTION;
4
LSMEANS trt/TDIFF;
5
RUN;
9 Code Block
DATA STEP Data
Explanation : Creation of the 'edu' dataset to compare different methods. The ' @@' option allows reading multiple observations per line.
INPUT method x y @code_sas_json/8_SAS_Intro_ReadFile_MultiCol_@@.json;
3
CARDS;
4
12939143411836
5
21735235382332
6
31383154333244
7
;
8
RUN;
10 Code Block
PROC GLM
Explanation : Analysis of Covariance (ANCOVA) on the 'edu' table to compare the effect of 'method' on 'y' while controlling for 'x'.
Copied!
PROC GLM data=edu ;
CLASS method;
MODEL y=method x /SOLUTION;
LSMEANS method/TDIFF;
RUN;
1
PROC GLMDATA=edu ;
2
CLASS method;
3
MODEL y=method x /SOLUTION;
4
LSMEANS method/TDIFF;
5
RUN;
11 Code Block
DATA STEP Data
Explanation : Creation of the 'na' table with three treatment groups (A, B, C).
Copied!
DATA na;
input trt $ x y @code_sas_json/8_SAS_Intro_ReadFile_MultiCol_@@.json;
cards;
A 11 6 A 8 0 A 5 2 A 14 8 A 19 11 A 6 4 A 10 13 A 6 1 A 11 8 A 3 0
B 6 0 B 6 2 B 7 3 B 8 1 B 18 18 B 8 4 B 19 14 B 8 9 B 5 1 B 15 9
C 16 13 C 13 10 C 11 18 C 9 5 C 21 23 C 16 12 C 12 5 C 12 16 C 7 1 C 12 20
;
RUN;
1
DATA na;
2
INPUT trt $ x y @code_sas_json/8_SAS_Intro_ReadFile_MultiCol_@@.json;
3
CARDS;
4
A 116 A 8 0 A 52 A 148 A 1911 A 64 A 1013 A 61 A 118 A 3 0
5
B 6 0 B 62 B 73 B 81 B 1818 B 84 B 1914 B 89 B 51 B 159
6
C 1613 C 1310 C 1118 C 95 C 2123 C 1612 C 125 C 1216 C 71 C 1220
7
;
8
RUN;
12 Code Block
PROC GLM
Explanation : Analysis of Covariance (ANCOVA) on the 'na' data.
Copied!
PROC GLM data=na ;
CLASS trt;
MODEL y=trt x /SOLUTION;
LSMEANS trt/TDIFF;
RUN;
1
PROC GLMDATA=na ;
2
CLASS trt;
3
MODEL y=trt x /SOLUTION;
4
LSMEANS trt/TDIFF;
5
RUN;
13 Code Block
DATA STEP Data
Explanation : Creation of the last example dataset, 'sale'.
INPUT type x y @code_sas_json/8_SAS_Intro_ReadFile_MultiCol_@@.json;
3
CARDS;
4
1382113926136221452813319
5
2433423826238292271823425
6
3242333229331303211632829
7
;
8
RUN;
14 Code Block
PROC GLM
Explanation : Final Analysis of Covariance on the 'sale' table to evaluate the effect of 'type' on 'y' by adjusting for the covariate 'x'.
Copied!
PROC GLM data=sale ;
CLASS type;
MODEL y=type x /SOLUTION;
LSMEANS type/TDIFF;
RUN;
1
PROC GLMDATA=sale ;
2
CLASS type;
3
MODEL y=type x /SOLUTION;
4
LSMEANS type/TDIFF;
5
RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.