The
SAS program below reads and calculates statistics for data on sample
of trucks. The prepared data that is
read by the program is here.
SAS log of the
program.
SAS
listing of the program.
Infile "C:\Documents
and Settings\mfinney\Desktop\fuelecon.dat";
Input
drive $ enginesize cylinder transmission $ MPG;
Proc contents;
Proc print;
Data
csladat2;
Proc means; var mpg cylinder; by
transmission;
Data
csladat3;
Set
csladat2;
Proc sort; by
cylinder;
Proc freq; tables mpg; by cylinder;
Data
csladat4;
Set
csladat1;
If
drive="4WD" then alldrive=1;else alldrive=0;
If
transmission="Auto" then autotrans=1;else autotrans=0;
Proc reg;
Model
mpg=alldrive enginesize autotrans;
Model
nlmpg=alldrive enginesize autotrans;
run;
The Data
statement opens a module in the SAS program in which you normally perform
operations such as read in and define variables, create variables etc. The word “Data” is part of the SAS program
language.
The Infile statement is directing
SAS to find an external (data) file to be read.
This is the location and filename of the
data the program is going to read in.
You define the variable names in the Input statement. Each column of data is considered a variable
and is given a name. Remember to have as
many names as columns of data. The $
sign indicates to SAS that the variable is non-numeric.
The Set
statement brings the variables created within the previous data step
(cslastat1) into the new data step (cslastat2).
Proc Means calculates summary statistics for the
variable MPG. If the “var MPG” isn’t included, SAS will calculate the statistics
for all the numerical variables in the data.
Proc Sort sorts the data by the variable you
designate. SAS will divide the data by
the two values the transmission variable takes on.
This calculates separate summary
statistics for the MPG and cylinder variables by the two different values of
transmission.
This if statement creates the dummy
variable, alldrive, which equals 1 if the vehicle is
four wheel drive and 0 if not.
This runs the linear regression
model estimating the determinants of miles per gallon for the vehicles in the
sample. The independent variables
include the alldrive and autotrans
dummy variables we created.
This creates a new variable named nlmpg which is the natural log of the variable mpg. The new name could be anything; it doesn’t
have to be nlmpg.
This runs the log/linear regression
model in which MPG is logged but all the right-hand-side variables are not
logged.
Name |
Drive |
Displacement |
Cylinders |
Transmission |
CityMPG |
|
1 |
C1500
SILVERADO |
2WD |
4.3 |
6 |
Auto |
15 |
2 |
C1500
SILVERADO |
2WD |
4.3 |
6 |
Manual |
15 |
3 |
C1500
SILVERADO |
2WD |
4.8 |
8 |
Auto |
15 |
4 |
C1500
SILVERADO |
2WD |
4.8 |
8 |
Manual |
16 |
5 |
C1500
SILVERADO |
2WD |
5.3 |
8 |
Auto |
11 |
6 |
C1500
SILVERADO |
2WD |
5.3 |
8 |
Auto |
15 |
7 |
C1500
SILVERADO |
2WD |
5.3 |
8 |
Auto |
15 |
8 |
SSR
PICKUP |
2WD |
5.3 |
8 |
Auto |
15 |
9 |
CHEVY
C2500 SILVERADO |
2WD |
6 |
8 |
Auto |
10 |
10 |
CHEVY
C2500 SILVERADO |
2WD |
6 |
8 |
Auto |
10 |
11 |
C1500
SIERRA |
2WD |
4.3 |
6 |
Auto |
16 |
12 |
C1500
SIERRA |
2WD |
4.3 |
6 |
Manual |
15 |
13 |
C1500
SIERRA |
2WD |
4.8 |
8 |
Auto |
15 |
14 |
C1500
SIERRA |
2WD |
4.8 |
8 |
Manual |
16 |
15 |
C1500
SIERRA |
2WD |
5.3 |
8 |
Auto |
11 |
16 |
C1500
SIERRA |
2WD |
5.3 |
8 |
Auto |
15 |
17 |
C1500
SIERRA |
2WD |
5.3 |
8 |
Auto |
15 |
18 |
K1500
SILVERADO |
4WD |
4.3 |
6 |
Auto |
14 |
19 |
K1500
SILVERADO |
4WD |
4.3 |
6 |
Manual |
14 |
20 |
K1500
SILVERADO |
4WD |
4.8 |
8 |
Auto |
14 |
21 |
K1500
SILVERADO |
4WD |
4.8 |
8 |
Manual |
14 |
22 |
K1500
SILVERADO |
4WD |
5.3 |
8 |
Auto |
10 |
23 |
K1500
SILVERADO |
4WD |
5.3 |
8 |
Auto |
13 |
24 |
K1500
SILVERADO |
4WD |
5.3 |
8 |
Auto |
14 |
25 |
S10
PICKUP |
4WD |
4.3 |
6 |
Auto |
15 |
26 |
S10
PICKUP |
4WD |
4.3 |
6 |
Manual |
14 |
27 |
K1500
SIERRA |
4WD |
4.3 |
6 |
Auto |
15 |
28 |
K1500
SIERRA |
4WD |
4.3 |
6 |
Manual |
14 |
29 |
K1500
SIERRA |
4WD |
4.8 |
8 |
Auto |
14 |
30 |
K1500
SIERRA |
4WD |
4.8 |
8 |
Manual |
14 |
31 |
K1500
SIERRA |
4WD |
5.3 |
8 |
Auto |
10 |
32 |
K1500
SIERRA |
4WD |
5.3 |
8 |
Auto |
13 |
33 |
K1500
SIERRA |
4WD |
5.3 |
8 |
Auto |
14 |
34 |
SONOMA |
4WD |
4.3 |
6 |
Auto |
15 |
35 |
SONOMA |
4WD |
4.3 |
6 |
Manual |
14 |
5.3 |
8 |
Auto |
15 |
|
2WD |
5.3 |
8 |
Auto |
15 |
2WD |
5.3 |
8 |
Auto |
15 |
2WD |
6 |
8 |
Auto |
10 |
2WD |
6 |
8 |
Auto |
10 |
2WD |
4.3 |
6 |
Auto |
16 |
2WD |
4.3 |
6 |
Manual |
15 |
2WD |
4.8 |
8 |
Auto |
15 |
2WD |
4.8 |
8 |
Manual |
16 |
2WD |
5.3 |
8 |
Auto |
11 |
2WD |
5.3 |
8 |
Auto |
15 |
2WD |
5.3 |
8 |
Auto |
15 |
4WD |
4.3 |
6 |
Auto |
14 |
4WD |
4.3 |
6 |
Manual |
14 |
4WD |
4.8 |
8 |
Auto |
14 |
4WD |
4.8 |
8 |
Manual |
14 |
4WD |
5.3 |
8 |
Auto |
10 |
4WD |
5.3 |
8 |
Auto |
13 |
4WD |
5.3 |
8 |
Auto |
14 |
4WD |
4.3 |
6 |
Auto |
15 |
4WD |
4.3 |
6 |
Manual |
14 |
4WD |
4.3 |
6 |
Auto |
15 |
4WD |
4.3 |
6 |
Manual |
14 |
4WD |
4.8 |
8 |
Auto |
14 |
4WD |
4.8 |
8 |
Manual |
14 |
4WD |
5.3 |
8 |
Auto |
10 |
4WD |
5.3 |
8 |
Auto |
13 |
4WD |
5.3 |
8 |
Auto |
14 |
4WD |
4.3 |
6 |
Auto |
15 |
4WD |
4.3 |
6 |
Manual |
14 |
1 The SAS System 16:40 Friday, April 2, 2010
NOTE: Copyright (c)
2002-2003 by SAS Institute Inc., Cary, NC, USA.
NOTE: SAS (r) 9.1
(TS1M3)
Licensed to CALIFORNIA
STATE UNIVERSITY LOS ANGELES - T&R, Site 0039713006.
NOTE: This session
is executing on the XP_PRO
platform.
NOTE: SAS 9.1.3
Service Pack 4
NOTE: SAS
initialization used:
real time 0.17 seconds
cpu
time 0.31 seconds
1 Data csladat1;
2 Infile "C:\Documents
and Settings\mfinney\Desktop\fuelecon.dat";
3 Input drive $ engine_size
cylinder transmission $ MPG;
NOTE: The infile "C:\Documents and Settings\mfinney\Desktop\fuelecon.dat"
is:
File Name=C:\Documents
and Settings\mfinney\Desktop\fuelecon.dat,
RECFM=V,LRECL=256
NOTE: 35 records
were read from the infile "C:\Documents and
Settings\mfinney\Desktop\fuelecon.dat".
The minimum record length was 75.
The maximum record length was 75.
NOTE: The data set WORK.CSLADAT1
has 35 observations and 5 variables.
NOTE: DATA
statement used (Total process time):
real time 0.01 seconds
cpu
time 0.01 seconds
4 Proc
contents;
NOTE: The PROCEDURE
CONTENTS printed page 1.
NOTE: PROCEDURE
CONTENTS used (Total process time):
real time 0.01 seconds
cpu
time 0.01 seconds
5 Proc print;
6
NOTE: There were 35
observations read from the data set WORK.CSLADAT1.
NOTE: The PROCEDURE
PRINT printed page 2.
NOTE: PROCEDURE
PRINT used (Total process time):
real time 0.00 seconds
cpu
time 0.00 seconds
7 Data csladat2;
8 Set csladat1;
NOTE: There were 35
observations read from the data set WORK.CSLADAT1.
2 The SAS
System 16:40 Friday, April
2, 2010
NOTE: The data set
WORK.CSLADAT2 has 35 observations and 5 variables.
NOTE: DATA
statement used (Total process time):
real time 0.00 seconds
cpu
time 0.00 seconds
9 Proc means;
var mpg;
NOTE: There were 35
observations read from the data set WORK.CSLADAT2.
NOTE: The PROCEDURE
MEANS printed page 3.
NOTE: PROCEDURE
MEANS used (Total process time):
real time 0.00 seconds
cpu
time 0.00 seconds
10 Proc sort;
by transmission;
NOTE: There were 35
observations read from the data set WORK.CSLADAT2.
NOTE: The data set
WORK.CSLADAT2 has 35 observations and 5 variables.
NOTE: PROCEDURE
SORT used (Total process time):
real time 0.00 seconds
cpu
time 0.00 seconds
11 Proc means; var mpg cylinder; by transmission;
12
NOTE: There were 35
observations read from the data set WORK.CSLADAT2.
NOTE: The PROCEDURE
MEANS printed page 4.
NOTE: PROCEDURE
MEANS used (Total process time):
real time 0.01 seconds
cpu
time 0.01 seconds
13 Data csladat3;
14 Set csladat2;
NOTE: There were 35
observations read from the data set WORK.CSLADAT2.
NOTE: The data set
WORK.CSLADAT3 has 35 observations and 5 variables.
NOTE: DATA
statement used (Total process time):
real time 0.00 seconds
cpu
time 0.00 seconds
15 Proc sort;
by cylinder;
NOTE: There were 35
observations read from the data set WORK.CSLADAT3.
NOTE: The data set
WORK.CSLADAT3 has 35 observations and 5 variables.
NOTE: PROCEDURE SORT
used (Total process time):
real time 0.01 seconds
cpu
time 0.00 seconds
3 The SAS
System 16:40 Friday, April
2, 2010
16 Proc freq; tables mpg; by cylinder;
17
NOTE: There were 35
observations read from the data set WORK.CSLADAT3.
NOTE: The PROCEDURE
FREQ printed pages 5-6.
NOTE: PROCEDURE
FREQ used (Total process time):
real time 0.01 seconds
cpu
time 0.01 seconds
18 Data csladat4;
19 Set csladat1;
20 nlmpg=log(mpg);
21 If drive="4WD" then all_drive=1;else all_drive=0;
22 If transmission="Auto" then auto_trans=1;else auto_trans=0;
23
24
NOTE: There were 35
observations read from the data set WORK.CSLADAT1.
NOTE: The data set
WORK.CSLADAT4 has 35 observations and 8 variables.
NOTE: DATA
statement used (Total process time):
real time 0.01 seconds
cpu
time 0.00 seconds
25 Proc reg;
26 Model mpg=all_drive
engine_size auto_trans;
27
28 Model nlmpg=all_drive engine_size auto_trans;
29
30
31 run;
NOTE: The PROCEDURE
REG printed pages 7-8.
NOTE: PROCEDURE REG
used (Total process time):
real time 0.03 seconds
cpu
time 0.01 seconds
NOTE: SAS Institute
Inc., SAS Campus Drive, Cary, NC USA 27513-2414
NOTE: The SAS
System used:
real time 0.37 seconds
cpu
time 0.40 seconds