Example B6 SAS PROGRAM

advertisement
Example B6
SAS PROGRAM
libname mylib 'C:\Documents and Settings\mervyn\My Documents\Classwork\stat479\';
data mylib.fueldat;
filename fueldd 'C:\Documents and Settings\mervyn\My Documents\Classwork\stat479\fuel.txt';
infile fueldd;
input (st pop tax numlic income roads fuelc)
( $2. 5. 2.1
5.
4.3
5.3
5.);
label pop='Population(in thousands)'
tax='Motor Fuel Tax Rate(in cents/gallon)'
numlic='No. of Licensed Drivers'
income='Per capita Income(in thsnds.)'
roads='Miles of Primary Highways(in thsnds.)' ;
percent=100*numlic/pop;
fuel=1000*fuelc/pop;
if income=<3.8 then incomgrp=1;
else if 3.8<income=<4.4 then incomgrp=2;
else incomgrp=3;
if tax<8.0 then taxgrp='Low ';
else taxgrp='High';
label percent='% of Population with Driving Licenses'
fuel='Fuel Consumption (in gallons/person)'
incomgrp='Per capita Income'
taxgrp='Fuel Tax'
state='State' ;
format percent 4.1 fuel 7. ;
state=stnamel(st);
drop fuelc;
run;
proc print label;
title 'Complete Data Set' ;
run;
SAS Log
2
libname mylib 'C:\Documents and Settings\mervyn\My Documents\Classwork\stat479\';
NOTE: Libref MYLIB was successfully assigned as follows:
Engine:
V9
Physical Name: C:\Documents and Settings\mervyn\My
Documents\Classwork\stat479
3
data mylib.fueldat;
4
filename fueldd 'C:\Documents and Settings\mervyn\My Documents\Classwork\stat479\fuel.txt';
5
infile fueldd;
6
input (st pop tax numlic income roads fuelc)
7
( $2. 5. 2.1
5.
4.3
5.3
5.);
8
9
label pop='Population(in thousands)'
10
tax='Motor Fuel Tax Rate(in cents/gallon)'
11
numlic='No. of Licensed Drivers'
12
income='Per capita Income(in thsnds.)'
13
roads='Miles of Primary Highways(in thsnds.)' ;
14
15
percent=100*numlic/pop;
16
17
fuel=1000*fuelc/pop;
18
19
if income=<3.8 then incomgrp=1;
20
else if 3.8<income=<4.4 then incomgrp=2;
21
else incomgrp=3;
22
23
if tax<8.0 then taxgrp='Low ';
24
else taxgrp='High';
25
26
27
28
29
30
31
32
33
34
35
36
37
label percent='% of Population with Driving Licenses'
fuel='Fuel Consumption (in gallons/person)'
incomgrp='Per capita Income'
taxgrp='Fuel Tax'
state='State' ;
format percent 4.1 fuel 7. ;
state=stnamel(st);
drop fuelc;
run;
NOTE: The infile FUELDD is:
File Name=C:\Documents and Settings\mervyn\My
Documents\Classwork\stat479\fuel.txt,
RECFM=V,LRECL=256
NOTE: 48 records were read from the infile FUELDD.
The minimum record length was 28.
The maximum record length was 28.
NOTE: The data set MYLIB.FUELDAT has 48 observations and 11 variables.
NOTE: DATA statement used (Total process time):
real time
0.09 seconds
cpu time
0.04 seconds
38
39
40
41
proc print label;
title 'Complete Data Set' ;
run;
NOTE: There were 48 observations read from the data set MYLIB.FUELDAT.
NOTE: PROCEDURE PRINT used (Total process time):
real time
0.01 seconds
cpu time
0.01 seconds
SAS Output
Complete Data Set
Obs
st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
ME
NH
VT
MA
RI
CT
NY
NJ
PA
OH
IN
IL
MI
WI
MN
IA
MO
Population
(in
thousands)
1029
771
462
5787
968
3082
18366
7367
11926
10783
5291
11251
9082
4520
3896
2883
4753
Motor Fuel
Tax Rate(in
cents/gallon)
No. of
Licensed
Drivers
9.0
9.0
9.0
7.5
8.0
9.0
8.0
8.0
8.0
7.0
8.0
7.5
7.0
7.0
7.0
7.0
7.0
540
441
268
3060
527
1760
8278
4074
6312
5948
2804
5903
5213
2465
2368
1689
2719
1
Per capita
Income(in
thsnds.)
3.571
4.092
3.865
4.870
4.399
5.342
5.319
5.126
4.447
4.512
4.391
5.126
4.817
4.207
4.332
4.318
4.206
Miles of
Primary
Highways(in
thsnds.)
1.976
1.250
1.586
2.351
0.431
1.333
11.868
2.138
8.577
8.507
5.939
14.186
6.930
6.580
8.159
10.340
8.508
Obs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
% of
Population
with Driving
Licenses
52.5
57.2
58.0
52.9
54.4
57.1
45.1
55.3
52.9
55.2
53.0
52.5
57.4
54.5
60.8
58.6
57.2
Fuel
Consumption (in
gallons/person)
541
524
561
414
410
457
344
467
464
498
580
471
525
508
566
635
603
Per
capita
Income
Fuel
Tax
State
1
2
2
3
2
3
3
3
3
3
2
3
3
2
2
2
2
High
High
High
Low
High
High
High
High
High
Low
High
Low
Low
Low
Low
Low
Low
Maine
New Hampshire
Vermont
Massachusetts
Rhode Island
Connecticut
New York
New Jersey
Pennsylvania
Ohio
Indiana
Illinois
Michigan
Wisconsin
Minnesota
Iowa
Missouri
Complete Data Set
Obs
st
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
ND
SD
NE
KS
DE
MD
VA
WV
NC
SC
GA
FL
KY
TN
AL
MS
AR
Population
(in
thousands)
632
579
1525
2258
565
4056
4764
1781
5214
2665
4720
7259
3299
4031
3510
2263
1978
Motor Fuel
Tax Rate(in
cents/gallon)
7.0
7.0
8.5
7.0
8.0
9.0
9.0
8.5
9.0
8.0
7.5
8.0
9.0
7.0
7.0
8.0
7.5
No. of
Licensed
Drivers
341
419
1033
1496
340
2073
2463
982
2835
1460
2731
4084
1626
2088
1801
1309
1081
2
Per capita
Income(in
thsnds.)
3.718
4.716
4.341
4.593
4.983
4.897
4.258
4.574
3.721
3.448
3.846
4.188
3.601
3.640
3.333
3.063
3.357
Miles of
Primary
Highways(in
thsnds.)
4.725
5.915
6.010
7.834
0.602
2.449
4.686
2.619
4.746
5.399
9.061
5.975
4.650
6.905
6.594
6.524
4.121
Obs
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
% of
Population
with Driving
Licenses
54.0
72.4
67.7
66.3
60.2
51.1
51.7
55.1
54.4
54.8
57.9
56.3
49.3
51.8
51.3
57.8
54.7
Fuel
Consumption (in
gallons/person)
714
865
640
649
540
464
547
460
566
577
631
574
534
571
554
577
628
Per
capita
Income
Fuel
Tax
State
1
3
2
3
3
3
2
3
1
1
2
2
1
1
1
1
1
Low
Low
High
Low
High
High
High
High
High
High
Low
High
High
Low
Low
High
Low
North Dakota
South Dakota
Nebraska
Kansas
Delaware
Maryland
Virginia
West Virginia
North Carolina
South Carolina
Georgia
Florida
Kentucky
Tennessee
Alabama
Mississippi
Arkansas
Complete Data Set
Obs
st
35
36
37
38
39
40
41
42
43
44
45
46
47
48
LA
OK
TX
MT
ID
WY
CO
NM
AZ
UT
NV
WA
OR
CA
Population
(in
thousands)
3720
2634
11649
719
756
345
2357
1065
1945
1126
527
3443
2182
20468
Motor Fuel
Tax Rate(in
cents/gallon)
8.0
7.0
5.0
7.0
8.5
7.0
7.0
7.0
7.0
7.0
6.0
9.0
7.0
7.0
No. of
Licensed
Drivers
1813
1657
6595
421
501
232
1475
600
1173
572
354
1966
1360
12130
3
Per capita
Income(in
thsnds.)
3.528
3.802
4.045
3.897
3.635
4.345
4.449
3.656
4.300
3.745
5.215
4.476
4.296
5.002
Miles of
Primary
Highways(in
thsnds.)
3.495
7.834
17.782
6.385
3.274
3.905
4.639
3.985
3.635
2.611
2.302
3.742
4.083
9.794
Obs
35
36
37
38
39
40
41
42
43
44
45
46
47
48
% of
Population
with Driving
Licenses
48.7
62.9
56.6
58.6
66.3
67.2
62.6
56.3
60.3
50.8
67.2
57.1
62.3
59.3
Fuel
Consumption (in
gallons/person)
487
644
640
704
648
968
587
699
632
591
782
510
610
524
Per
capita
Income
Fuel
Tax
State
1
2
2
2
1
2
3
1
2
1
3
3
2
3
High
Low
Low
Low
High
Low
Low
Low
Low
Low
Low
High
Low
Low
Louisiana
Oklahoma
Texas
Montana
Idaho
Wyoming
Colorado
New Mexico
Arizona
Utah
Nevada
Washington
Oregon
California
Download