Вы находитесь на странице: 1из 260

SAS:

SAS:

1 SAS/Base ...... 1-1


1.1 ... 1-3
1.2 SAS .......................................................................................... 1-5
1.3 SAS .......... 1-12
1.4 SAS ... 1-15
1.5 SAS ... 1-17
1.6 1-19

2 SAS .... 2-1


2.1 . 2-3
2.2 SAS .. 2-5
2.3 SAS ....... 2-9

3 SAS .. 3-1
3.1 .... 3-3
3.2 .... 3-5
3.3 .... 3-7

4 ............................................................... 4-1
4.1 .......................................................................... 4-3
4.2 ..................................................................... 4-8
4.3 ................................................................. 4-13
4.4 ...................................................................... 4-17
4.5 .......................................................................... 4-20
4.6 ........................................................... 4-24

5 .............................................. 5-1
5.1 FORMAT ............................................................. 5-3
5.2 VALUE ................................................................ 5-5
5.3 .............................................. 5-8

iii

iv

6 ................................................................................ 6-1
6.1 ..................................................................................................... 6-3
6.2 . 6-6
6.3 STOP POINT .. 6-15
6.4 .. 6-17
6.5 6-19

7 ................................................................. 7-1
7.1 ........................................................................................ 7-3
7.2 ....................................................................................... 7-6

8 SQL .......... 8-1


8.1 SQL ............................................................................ 8-3
8.2 SQL .................................................................... 8-6
8.3 ..................................... 8-11
8.4 .................................................................... 8-15
8.5 ....................................................... 8-17

9 ................................................... 9-1
9.1 ................................................................................ 9-3
9.2 ........................................................................ 9-5
9.3 ............................................................................... 9-8
9.4 .............................................................................................. 9-10
9.5 .................................................. 9-12
9.6 .................................................................. 9-20
9.7 .............................................. 9-23

10 .......................................................10-1
10.1 ......................................... 10-3
10.2
PROC UNIVARIATE ............................................................................... 10-12
10.3 MEANS ...................... 10-15
10.4
FREQ .................................................................................... 10-18
10.5 CORR .................................... 10-20
10.6 PROC REG
.................................................................................................... 10-22
10.7 ANOVA
........................................................................ 10-26

11 SAS ..............11-1
11.1 SAS ............................................................................ 11-3
11.2 ........................................................................ 11-7
11.3 INPUT ........................ 11-11
11.4 PUT ............................. 11-15
11.5 SAS .................... 11-19
11.6 .................................................... 11-36

vi

1 SAS/Base

1.1 ... 1-3


1.2 SAS .......................................................................................... 1-5
1.3 SAS .......... 1-12
1.4 SAS ... 1-15
1.5 SAS ... 1-17
1.6 1-19

1-2

1 SAS/Base

1.1

1-3

1.1.
BASE SAS, ,
:


,
.
,
, .. , .
, , ,
, .
() .
SAS :
() .
- *.dat, *.txt, *.csv
, , .SAS;
, - .SAS7BDAT
SAS
(Oracle, Dbase, Exel )
SAS

.
SAS
SAS

1-4

1 SAS/Base

,
.
,
90% 10%
.

1.2 SAS

1.2. SAS
SAS :
, , .
SAS . SAS
,
. SAS ,
, .

.
SAS
SAS : (DATA
step) (PROC step).

SAS
.

1-5

1-6

1 SAS/Base

SAS

1.2 SAS

(DATA step)
SAS .
.
,

SAS


SAS (
,
).

(PROC step)
() /
.
SAS , .
,



/,

DATA PROC
. ,
.
,
.
,
. , ,
,
,
.
SAS
, ,
(Basic, Cobol, Fortran) ,
(Assembler). SAS
4GL. , 4GL,
. SAS
.

1-7

1-8

1 SAS/Base


-
- (;)
, ,

.
,
DATA, - PROC.
1 DATA, 2 SET , 3 RUN, 4
PROC PRINT, 5 RUN.

1.2 SAS

SAS
, 4GL,
:
.
,
.

, .. .

.
.

.
, . , ,
,
, .
,

.

.
:
(*)
(;)

(/*)
(*/)
- ,
(/*),
,
.
SAS

.
.
()
. DATA PROC
.
(
DATA PROC) RUN QUIT,
.
RUN.

1-9

1-10

1 SAS/Base

(DATA or PROC)
, RUN

.



log-. LOG
.
SAS , LOG
.
SAS Log
1
2
3

data clinic.admit2;
set clinic.admit;
run;

NOTE: The data set CLINIC.ADMIT2 has 21


observations and 9 variables.
NOTE: The DATA statement used 1.03 seconds
4
5

proc print data=clinic.admit2;


run;

NOTE: The PROCEDURE PRINT used 0.2 seconds.

1.2 SAS


, :

SAS Clinic.Admit2.
LOG .


Clinic.Admit2:

Obs ID Name

Sex Age Date Height Weight ActLevel

Fee

1 2458 Murray, W

27

72

168 HIGH

85.20

2 2462 Almers, C

34

66

152 HIGH

124.80

3 2501 Bonaventure, T F

31

17

61

123 LOW

149.75

4 2523 Johnson, R

43

31

63

137 MOD

149.75

5 2539 LaMance, K

51

71

158 LOW

124.80

6 2544 Jones, M

29

76

193 HIGH

124.80

7 2552 Reberson, P

32

67

151 MOD

149.75

8 2555 King, E

35

13

70

173 MOD

149.75

9 2563 Pitts, D

34

22

73

154 LOW

124.80

10 2568 Eberhardt, S

49

27

64

172 LOW

124.80

11 2571 Nunnelly, A

44

19

66

140 HIGH

149.75

12 2572 Oberon, M

28

17

62

118 LOW

85.20

13 2574 Peterson, V

30

69

147 MOD

149.75

14 2575 Quigley, M

40

69

163 HIGH

124.80

15 2578 Cameron, L

47

72

173 MOD

124.80

16 2579 Underwood, K M

60

22

71

191 LOW

149.75

17 2584 Takahashi, Y

43

29

65

123 MOD

124.80

18 2586 Derber, B

25

23

75

188 HIGH

85.20

1-11

1-12

1 SAS/Base

1.3. SAS
SAS
SAS . SAS
SAS, .
.
SAS
SAS. , WORK,
.
.
, (OS/2, DOS, Windows, UNIX) SAS
, ,
.

...

SAS ...

Windows, UNIX,
OpenVMS, OS/2
(

SAS-, .

, SAS-
.

CMS

SAS-, .

OS/390 (MVS)

host,
SAS-.

1.3 SAS


.
SAS
SAS.
WORK,
.
.
.
:

SAS

SAS.


(
Work),
.
,

().

:
SAS,

Work.
SAS

SAS.

, Clinic
, ,

..

1-13

1-14

1 SAS/Base

.
SAS
:
libref.filename
,
, .
. ,
, , WORK.
.

, , Clinic.Admit ,
Admit , Clinic.

1.4 SAS

1.4. SAS
SAS
SAS-,
, Work
. , Work.Test
SAS- Test, Work
SAS

SAS-

, (
). ,
, , - Work. ,
Test SAS-
Test, Work
SAS

SAS-,

1-15

1-16

1 SAS/Base

SAS
,
. :
32 ;

;

, ,
(%$!*&#@);

.

, .
MyBirthday, MYBIRTHDAY, mYBIrthdAy.
SAS . ,
,
.
SAS:

Payroll
LABDATA1995_1997
_EstimatedTaxPayments3

1.5 SAS

1.5. SAS
SAS
, SAS . SAS
. SAS (, ),

.
SAS
SAS , SAS, .

(Data Portion)
(Description Portion).
, , ,
.. ,
,
, . SAS
,
-,
.

SAS
SAS
General Data Set Information

*Data Set Name*Data Set Label


*Date/Time Created*Storage Information
*Number of Observations
*Number of Variables
Information for Each Variable
*Name*Informat*Length*Label
*Type*Format*Position
IDNUM

NAME

1351
Farr, Sue
161
212
Moore, Ron
2512
Ruth, G H
2532
Hobbs, Roy
...
...
...
5151
Coxe, Susan

WAGECAT

WAGERATE

S
S
S
S
H

3392.50
5093.75
.
1572.50
13.48

3163.00

23

1-17

1-18

1 SAS/Base


SAS ,

SAS . , ,
Clinic.Insure,
. (
.)

Data Set Name:


Member Type:
Engine:
Created:
Observations:
Variables:
Indexes:
Observation Length:

CLINIC.INSURE
DATA
V8
10:05 Tuesday, March 30, 1999
21
7
0
64


SAS ,
-,
.
, Jones, - 158.3
48 - .

Name
Jones
Laverne
Jaffe
Wilson

Sex
M
M
F
M

Age
48
58
.
28

Weight
128.6
158.3
115.5
170.1

1.6

1.6.
()
( ) ,
. Jones, M, 48, 128.6
.

Name
Jones
Laverne
Jaffe
Wilson

Sex
M
M
F
M

Age
48
58
.
28

Weight
128.6
158.3
115.5
170.1

,
. SAS
.

()
( )
- .
Jones, Laverne, Jaffe, Wilson
Name.

Name
Jones
Laverne
Jaffe
Wilson

Sex
M
M
F
M

Age
48
58
.
28

Weight
128.6
158.3
115.5
170.1

Name, Sex, Age, Weight. SAS


.

1-19

1-20

1 SAS/Base


,

.
SAS
(missing) : ,

Name
Jones
Laverne
Jaffe
Wilson

Sex
M
M
F
M

Age
48
58
.
28

Weight
128.6
158.3
115.5
170.1


. ,
.
(name), (type), (length),
(informat) (format) ,
(label).
Name
-----Policy
Total
Name

Type Length Format


Informat
---- ------ --------- -------Num
8
Num
8
Char
20
DOLLAR8.2 COMMA10.

Label
------------Policy Number
Total Balance
Patient Name

1.6

1-21



,
SAS .
1 32767 .
8 .

Name
-----Policy
Total
Name

Type Length Format


Informat
---- ------ --------- -------Num
8
Num
8
Char
20
DOLLAR8.2 COMMA10.

Label
------------Policy Number
Total Balance
Patient Name

, Name,
.

, Age, .
Name
Laverne
Jaffe
Wilson

Sex
M
M
F
M

Age
48
58
.
28

Weight
128.6
158.3
115.5
170.1


. ,
8 ,
1 1960:

1-22

1 SAS/Base

SAS

SA S / 1
1960 .

1jan1959

1jan1960

1jan1961

1jan2000

D A TE9.Inform at

-365

01/

01/

19 5

366

14610

M M D D YY 10.Form at
01/
01/
01/
01/
196
196
0
1

01/

01/

200

(
) .

32K
. Name 20 .

8 .
( )

( ).
Name
-----Policy
Total
Name

Type Length Format


Informat
---- ------ --------- -------Num
8
Num
8
Char
20
DOLLAR8.2 COMMA10.

Label
------------Policy Number
Total Balance
Patient Name

2 SAS

2.1 .... 2-3


2.2 SAS .. 2-5
2.3 SAS ....... 2-9

2-2

2 SAS

2.1

2-3

2.1.
SAS
.
SAS Windows
. : (Program Editor),
(Log) (Output).

. .
, , /
.
. ,
.
, ,
.
. ,
.

2-4

2 SAS

SAS
SAS: Explorer, Program Editor, Log, Output Results.
Windows Program Editor Enhanced
Editor ( - Editor.)

2.2 SAS

2.2. SAS
SAS ,
. , , :

,

.

2-5

2-6

2 SAS

2.2 SAS

2-7

SAS Windows ,
.
.
:
-

Toolbar

Submit

2-8

2 SAS

( - F3).

Keys .


.
, .

2.3 SAS

2.3. SAS
(Explorer)

SAS ,
..
:

SAS
SAS
,

Explorer (
).

2-9

2-12

2 SAS

(Program Editor)

, ,
.
.
View Program Editor.

SAS , drag and


drop,
. : File
Open.

(Enhanced Editor)

Windows,
. ,
, .
.
View Enhanced Editor.

2.3 SAS


(Alt or Shift plus keystroke)
(undo)

Log

Log
. Log ,
View Log.

2-11

2-12

2 SAS

Output

(.. )
HTML.

Output
, Output Log.
Output,
.
Output , View

Output.

SAS Output.
Log.

2.3 SAS

Results

Results
, SAS .
, ,
.
, Results Explorer
, , .
Results () HTML ..
Results , View

SAS
(, pgm, output, log, explorer) .
SAS
, .

Results.

2-13

2-14

2 SAS

3 SAS

3.1 .... 3-3


3.2 .... 3-5
3.3 .... 3-7

3-2

3 SAS

3.1

3-3

3.1.
SAS
SAS .
() :
SAS ( )

LIBNAME.
.

LIBNAME:
LIBNAME libref 'SAS-data-library';

libref 1 8 (
SAS).

SAS-data-library
(
Windows, OS/2 ).

: LIBNAME
Clinic D:\Users\Qtr\Reports.
libname clinic 'd:\users\qtr\reports';

Windows

c:\fitness\data

UNIX

/users/april/fitness/sasdata

OpenVMS

dua0:[april.fitness]

CMS

OS/390

april.fitness.sasdata

3-4

3 SAS


LIBNAME Log ,
.

3.2

3.2.

.


SAS
Admit, ,
Clinic.

, PRINT Clinic.Admit,
:
proc print data=clinic.admit;

run;


LIBNAME SAS ,
.
(engine)

, .

3-5

3-6

3 SAS


SAS
, LIBNAME
.
LIBNAME libref engine 'SAS-data-library';

libref 1 8 (
SAS).

engine .

SAS-data-library
(
Windows, OS/2 ).

, LIBNAME, ,
Rptdata SPSS
G:\Myspss.dat Windows.
libname rptdata spss 'g:\myspss.dat';
SAS/ACCESS
SAS/ACCESS,
, .

SAS/ACCESS
.
PC
ORACLE

ADABAS

Excel (.xls)

SYBASE

IMS/DL-I

Lotus (.wkn)

Informix

CA-IDMS

DBF

DB2 for OS/390

SYSTEM 2000

DIF

3.2

3.3.


SAS.

, SAS,
Explorer. (, , ,
) Active Libraries.


(double-click) (
Libraries Open). View Details
.

3-7

3-8

3 SAS



, (,
Open). VIEWTABLE.

3.2



CONTENTS, ( ),
.

CONTENTS:
PROC CONTENTS DATA=libref._ALL_ NODS;
RUN;

libref .

_ALL_
. ( (.) _ALL_
)

NODS
.

3-9

3-10

3 SAS

Mylib
:
proc contents data=mylib._all_ nods;
run;

, , ,
Mylib.

-----Directory----Libref:

CLINIC

Engine:

V8

Physical Name: C:\WINNT\Profiles\Personal\My SAS Files\V8


File Name:

C:\WINNT\Profiles\Personal\My SAS Files\V8

# Name

Memtype File Size Last Modified

1 ADMIT

DATA

9216 23JUN2000:16:30:38

2 ADMITJUNE DATA

9216 23JUN2000:16:30:38

3 COMPANY DATA

5120 23JUN2000:16:30:38

4 CREDIT

DATA

5120 23JUN2000:16:30:38

5 CUSTDET1 DATA

33792 04MAY2000:13:45:49

6 DIABETES

DATA

7 DMDATA

CATALOG

9216 23JUN2000:16:30:38
21504 04MAY2000:13:59:19

4.1 .......................................................................... 4-3


4.2 ..................................................................... 4-8
4.3 ................................................................. 4-13
4.4 ...................................................................... 4-17
4.5 .......................................................................... 4-20
4.6 ........................................................... 4-24

4-2

4.1

4-3

4.1.
.
- ,

, . ,
, ,
SAS. .
:

SAS
SAS
SAS
( )

, , , ,
.
SAS . SAS
:

Base SAS (
), (Viewtable window).
.
()
, , .

(SAS/FSP
Full Screen Product)

. SAS/FSP
.

SAS .
. SAS
:

(DATA Step)
.

IMPORT
(Import Wizard)
, .

4-4

SAS . ,
,
.
SAS:

(Dynamic Data Exchange DDE),


,
Windows,
Windows

IMPORT
(Import Wizard) ,
Excel, Lotus, dBase, Microsoft Access,
SAS
SAS/ACCESS for PC File Formats.

DDE /
SAS/ACCESS, ,
IMPORT Wizard .
(CSV-), .

( ).
SAS
SAS .
, ,
, ( ) .

SAS/ACCESS .

.

,
. SPSS, OSIRIS
.
.

-
SAS, , SAS
. SAS ,
, .
, .

4.1

4-5

. ,
. ,
, / .
SAS DATALINES.
, DATALINES
. DATALINES
.
. DATALINES
, . DATALINES
CARDS. DATALINES CARDS
. DATALINES
. ( INPUT,
.
)

, . ,
, .
INFILE.
( DATA) INPUT. INFILE
, .
:
Windows, NT, OS/2:
UNIX:
OS/390:

INFILE C:\MyDIR\List.dat;
INFILE /home/mydir/List.dat;
INFILE MYID.LIST.DAT;

4-6

, Mydir
List.dat:
30 185 78
41 194 103
90 60 90
:

, . ,
, (free formatted input).
. .
-
, .

8 (
LENGTH).
,
, . , -
,
(.).
:
30 185 78
41 194 103
90 60 90
25 . 56.5
. 172
87.7
. . 67

4.2

4-7

- Name$, age, growth, weight.


Name$ - , .
, . ,
weight .
, SAS ,
INPUT. , ,
(Example_1.sas).


. ,
, .
,
. ,
, , .
.

4-8

4.2.
:

;
;
;
( ) .

INPUT :
INPUT variable $ startcol-endcol ;

INPUT ,
, ,
($)
.
, .
, ,

1
2
1--- 5 ---- 0---5----- 0-- - -5
Pentium II
Pentium III

2338 32
45019.2128

1 15, 16 18
, 19 22 -
, 23 25 .
INPUT :
INPUT Name_Comp $ 1-15
Tact 16-18
Hard 19-22
OZU 23-25;

4.2

4-9

, ,
:

. ?
, 1000000, 1,000,000.

.
,
, .
.
, : , SAS
1 1960 .
.
20-11-2000 20.11.2000 20NOV2000.

.
,
:

$NameFormatW.

NameFormatW.D

NameFormatW.

$ , NameFormat
, W , , D
( ).
: $W.
W.D .
(.) ,
.

4-10

INPUT :
INPUT Name_Comp $15. Tact 3. Hard 4. OZU 3. Data_ Purchase DDMMYY10. ;

. Tact
( - 3.) 16 ( Name_Comp
$15.) . ,
Data_ Purchase, 10 26 (15+3+4+6
) 10 , ..
SAS .
.
.
Attempt.dat , , (yes/no), :

11-03-75 n
29-02-76 y
31-05-78 n
25-11-75 n

3 8.93 9.08 9.17


2 10.4510.8011.90
3 8.97 9.2510.10
2 7.56 8.55 8.90

SAS JUMP .
INPUT.
DATA Jump;
INFILE C:\My_Data\Attempt.dat;
INPUT Familia $10. Name $8. Date DDMMYY8. +1 Test $1. +1 Wind 1.
+1 (Att_1 Att_2 Att_3) (5.2);
RUN;
Familia Name $10. $8. ,
, 10 8 . 8 ,
SAS DDMMYY8.,
(25-11-75 25/11/75). +1 - ,
. Test .
Wind.
,
.

. , ,
. ,
.
.

4.2

4-11

:
:



11-03-75 n 1,005,075
29-02-76 yes 28,456,100
31-05-78 no
2,213,656
25-11-75 no
1,532,934

:
, 17- ,
33-
, .
:
DATA Test_Doping;
INFILE C:\My_Data\Attempt.dat;
INPUT Familia $ Name $ @17 Date DDMMYY8. +1 Test $
@33 Value COMMA10. ;
RUN;
,
. PRINT (
)
PROC PRINT Data=Test_Doping;
RUN;

4-12

, SAS .
.
.. ,
.
FORMAT, :
FORMAT Date DDMMYY10.;
.
.
, , SAS
.
SAS .
SAS ,
. ,
.
Value ,
( @33 Value COMMA10. , .. @33),
( ):



11-03-75 n * 1,005,075
29-02-76 yes * 28,456,100
31-05-78 no * 2,213,656
25-11-75 no * 1,532,934

, ,
.

4.3

4.3.
,
, .
PRINT.
PROC PRINT :
PROC PRINT <DATA=SAS-data-set>;
RUN;
SAS-data-set ,
, , ,
Output Therapy
Patients.
libname patients 'c:\records\patients';
proc print data=patients.therapy;
run;

. ,




.
Obs

Date

AerClass WalkJogRun Swim

1 JAN1999

56

78

14

2 FEB1999

32

109

19

3 MAR1999

35

106

22

4 APR1999

47

115

24

5 MAY1999

55

121

31

6 JUN1999

61

114

67

7 JUL1999

67

102

72

8 AUG1999

64

76

77

9 SEP1999

78

77

54

10 OCT1999

81

62

47

11 NOV1999

84

31

52

4-13

4-14

, PROC PRINT ,
.
VAR.

VAR:
VAR variable(s);
variable(s) , .

, VAR Age,
Height, Weight, Fee :
proc print data=clinic.admit;
var age height weight fee;
run;

Obs Age Height Weight

Fee

27

72

168

34

66

152 124.80

31

61

123 149.75

43

63

137 149.75

51

71

158 124.80

29

76

193 124.80

25

67

151 149.75

27

70

173 149.75

34

73

154 124.80

10

49

64

172 124.80

11

44

66

140 149.75

85.20


- Obs. ,

4.3

OBS
Obs PROC PRINT
NOOBS.
proc print data=work.example noobs;
var age height weight fee;
run;

Age Height Weight Fee


27

72

168

85.20

34

66

152 124.80

31

61

123 149.75

43

63

137 149.75

51

71

158 124.80

, PROC PRINT
. ,
WHERE PROC PRINT .

WHERE:
WHERE where-expression;
where-expression . Where-expression
SAS .

, WHERE
Age 30:
proc print data=clinic.admit;
var age height weight fee;
where age>30;
run;

4-15

4-16

Obs Age Height Weight

Fee

34

66

152 124.80

31

61

123 149.75

43

63

137 149.75

51

71

158 124.80

34

73

154 124.80

10

49

64

172 124.80

11

44

66

140 149.75

WHERE
WHERE ,
, VAR.
WHERE
:

= eq

where name='Jones, C.';

^= ne

where temp ne 212;

> gt

where income>20000;

< lt

where partno lt "BG05";

>= ge

where id>='1543';

<= le

where pulse le 85;

WHERE

where age<=55 and pulse>75;


where area='A' or region='S';
where ID>1050 and state='NC';

where actlevel='LOW' or actlevel='MOD';


where fee=124.80 or fee=178.20;

where actlevel in ('LOW','MOD');


where fee in (124.80,178.20);

where (age<=55 and pulse>75) or area='A';

where age<=55 and (pulse>75 or area='A');

4.4

4.4.
, PROC PRINT ,
.
PROC SORT. SORT

SAS
SAS ,

()
.

PROC SORT:
PROC SORT DATA=SAS-data-set <OUT=SASdata-set>;
BY <DESCENDING> BY-variable(s);
RUN;

DATA=
OUT= ,

BY-variable(s) BY

DESCENDING BY

OUT= ,
(
).

4-17

4-18

Wgtadmit
Clinic.Admit Weight.
PROC PRINT Wgtadmit
.
proc sort data=clinic.admit out=work.wgtadmit;
by weight;
run;
proc print data=work.wgtadmit;
var age height weight fee;
where age>30;
run;

Obs Age Height Weight

Fee

31

61

123 149.75

43

65

123 124.80

43

63

137 149.75

44

66

140 149.75

41

67

141 149.75

32

67

151 149.75

10

34

66

152 124.80

11

34

73

154 124.80

4.4

DESCENDING .
proc sort data=clinic.admit out=work.wgtadmit;
by descending weight;
run;
proc print data=work.wgtadmit;
var age height weight fee;
where age>30;
run;

Obs Age Height Weight

Fee

60

71

191 149.75

54

71

183 149.75

35

70

173 149.75

47

72

173 124.80

49

64

172 124.80

40

69

163 124.80

10

51

71

158 124.80

11

34

73

154 124.80

4-19

4-20

4.5.

PRINT SUM.

SUM:
SUM variable(s);
variable(s) , .

VAR.

SUM PRINT
BalanceDue:
proc print data=clinic.insure;
var name policy balancedue;
where pctinsured < 100;
sum balancedue;
run;

Obs Name
2 Almers, C

Policy BalanceDue
95824

156.05

3 Bonaventure, T 87795

9.48

4 Johnson, R

39022

61.04

5 LaMance, K

63265

43.68

6 Jones, M

92478

52.42

7 Reberson, P

25530

207.41

8 King, E

18744

27.19

9 Pitts, D

60976

310.82

10 Eberhardt, S

81589

173.17

11 Peterson, V

75986

228.00

1269.26

4.5



.
SUM BY.

BY:
BY <DESCENDING> BY-variable-1
<...<DESCENDING> <BY-variable-n>> ;

BY-variable
.

DESCENDING ,

.

SUM PRINT
Fee
ActLevel .
proc sort data=clinic.admit out=work.activity;
by actlevel;
run;
proc print data=work.activity;
var age height weight fee;
where age>30;
sum fee;
by actlevel;
run;

4-21

4-22

ActLevel=HIGH
Obs Age Height Weight

Fee

34

66

152

124.80

44

66

140

149.75

40

69

163

124.80

41

67

141

149.75

ActLevel

549.10
ActLevel=LOW

Obs Age Height Weight

Fee

31

61

123

149.75

51

71

158

124.80

10

34

73

154

124.80

11

49

64

172

124.80

13

60

71

191

149.75

ActLevel

673.90
ActLevel=MOD

Obs Age Height Weight

Fee

15

43

63

137

149.75

16

32

67

151

149.75

17

35

70

173

149.75

19

47

72

173

124.80

20

43

65

123

124.80

21

54

71

183

149.75

ActLevel

848.60
2071.60

,
Obs, ,
:

4.5

ActLevel Age Height Weight


HIGH

34

66

152

124.80

44

66

140

149.75

40

69

163

124.80

HIGH
LOW

399.35
31

61

123

149.75

51

71

158

124.80

34

73

154

124.80

49

64

172

124.80

LOW
MOD

MOD

Fee

524.15
43

63

137

149.75

32

67

151

149.75

35

70

173

149.75

47

72

173

124.80

43

65

123

124.80

54

71

183

149.75

848.60
1772.10

ID
BY . ID

Obs

ID/BY

ID/BY
.

, :
proc sort data=clinic.admit out=work.activity;
by actlevel;
run;
proc print data=work.activity;
var age height weight fee;
where age>30;
sum fee;
by actlevel;
id actlevel;
run;

4-23

4-24

4.6.

, PRINT,
.
PAGEBY.
PAGEBY:
PAGEBY BY-variable;
BY-variable , BY.

PAGEBY
ActLevel,
.
proc sort data=clinic.admit out=work.activity;
by actlevel;
run;
proc print data=work.activity;
var age height weight fee;
where age>30;
sum fee;
by actlevel;
id actlevel;
pageby actlevel;
run;

4.6

ActLevel Age Height Weight


HIGH

34

66

152

124.80

44

66

140

149.75

40

69

163

124.80

HIGH

399.35

ActLevel Age Height Weight


LOW

61

123

149.75

51

71

158

124.80

34

73

154

124.80

49

64

172

124.80

524.15

ActLevel Age Height Weight

MOD

Fee

31

LOW

MOD

Fee

Fee

43

63

137

149.75

32

67

151

149.75

35

70

173

149.75

47

72

173

124.80

43

65

123

124.80

54

71

183

149.75

848.60
1772.10

4-25

4-26


PROC PRINT ,

. :


LABEL
LABEL PRINT ,
,
.

LABEL:
LABEL variable1='label1'
variable2='label2'
... ;
256
.

WalkJogRun
Walk/Jog/Run.
LABEL PRINT.
proc print data=clinic.therapy label;
label walkjogrun='Walk/Jog/Run';
run;

Obs

Date

AerClass Walk/Jog/Run Swim

1 JAN1999

56

78

14

2 FEB1999

32

109

19

3 MAR1999

35

106

22

4 APR1999

47

115

24

5 MAY1999

55

121

31

6 JUN1999

61

114

67

7 JUL1999

67

102

72

8 AUG1999

64

76

77

9 SEP1999

78

77

54

10 OCT1999

81

62

47

11 NOV1999

84

31

52

4.6


LABEL
. . .
proc print data=clinic.admit label;
var age height;
label age='Age of Patient';
label height='Height in Inches';
run;

. . . LABEL
.
proc print data=clinic.admit label;
var actlevel height weight;
label actlevel='Activity Level'
height='Height in Inches'
weight='Weight in Pounds';
run;


,
.
FORMAT,
.
Format ,
.

FORMAT:
FORMAT variable(s) format-name;

variable(s) 6
format-name SAS
,
.

4-27

4-28


( ),
.

FORMAT ...

...

format date mmddyy6.;

MMDDYY6.
Date

format net comma5.0


gross comma8.2;

COMMA5.0
Net
COMMA8.2
Gross

format net gross dollar9.2; DOLLAR9.2


Net Gross

, FORMAT
Fee , :
proc print data=clinic.admit;
var actlevel fee;
where actlevel='HIGH';
format fee dollar4.;
run;

Obs ActLevel Fee


1 HIGH

$85

2 HIGH

$125

6 HIGH

$125

11 HIGH

$150

14 HIGH

$125

18 HIGH

$85

20 HIGH

$150

4.6

SAS

.

COMMAw.d

...

comma8.2


dollar6.2
DOLLARw.d
mmddyy10.
MMDDYYw. 09/12/97
(MMDDYY8.) 09/12/1997
(MMDDYY10.)
7.

w.
8.2
d ,
w.d
w
$12.
w
$w.
date9.
16OCT99 (DATE7.)
DATEw.
16OCT1999 (DATE9.)

,
.

38245.3975

COMMA12.2

38,245.40

38245.3975

12.2

38245.40

38245.3975

DOLLAR12.2

$38,245.40

38245.3975

DOLLAR9.2

$38245.40

38245.3975

DOLLAR8.2

38245.40

MMDDYY8.

01/01/60

MMDDYY10.

DATE7.

01JAN60

DATE9.

01JAN1960

01/01/1960

4-29

4-30



, , TITLE.
, ,
FOOTNOTE.
- , TITLE FOOTNOTE ,
PRINT.
.

TITLE FOOTNOTE:
TITLE<n> 'text';
FOOTNOTE<n> 'text';
n 1 10, ,
, 'text' . title
footnote ,
LINESIZE= .
, title title1
( footnote footnote1).
,
The SAS System.
, .

:
1 3
.
title1 'Heart Rates for Patients with';
title3 'Increased Stress Tolerance Levels';
proc print data=clinic.stress;
var resthr maxhr rechr;
where tolerance='I';
run;

4.6

Heart Rates for Patients with


Increased Stress Tolerance Levels
OBS
2
3
8
11
14
15
20

RestHR

MaxHR

RecHR

68
78
70
65
74
75
78

171
177
167
181
152
158
189

133
139
122
141
113
108
138

- FOOTNOTE :
footnote1 'Data from Treadmill Tests';
footnote3 '1st Quarter Admissions';
proc print data=clinic.stress;
var resthr maxhr rechr;
where tolerance='I';
run;

Obs RestHR MaxHR RecHR


2

68

171

133

78

177

139

70

167

122

11

65

181

141

14

74

152

113

15

75

158

108

20

78

189

138

Data from Treadmill Tests


1st Quarter Admissions

4-31

5.1 FORMAT ............................................................. 5-3


5.2 VALUE ................................................................ 5-5
5.3 .............................................. 5-8

5-2

5.1 FORMAT

5.1. FORMAT
, .
,
JobTitle Perm.Empinfo PRINT.

Obs FirstName LastName JobTitle Salary


1 Donny

Evans

112 29996.63

2 Lisa

Helms

105 18567.23

3 John

Higgins

111 25309.00

4 Amy

Larson

113 32696.78

5 Mary

Moore

112 28945.89

6 Jason

Powell

103 35099.50

7 Judy

Riley

111 25309.00

8 Neal

Ryan

112 28180.00

,
JobTitle.
SAS .
.

Obs FirstName LastName JobTitle

Salary

1 Donny

Evans

technical writer

29996.63

2 Lisa

Helms

text processor

18567.23

3 John

Higgins

assoc. technical writer 25309.00

4 Amy

Larson

senior technical writer 32696.78

5 Mary

Moore

technical writer

28945.89

6 Jason

Powell

manager

35099.50

7 Judy

Riley

assoc. technical writer 25309.00

8 Neal

Ryan

technical writer

9 Henry

Wilson

senior technical writer 31875.46

Woods

text processor

10 Chip

28180.00
17098.71

FORMAT,
.

5-3

5-4

FORMAT:
PROC FORMAT <options>;
options

LIBRARY=libref - ,
,
FMTLIB ,
.


. ,
. LIBRARY= ,
Work.Formats.
Work,
SAS.

, ,
.
Formats.
libname library 'c:\sas\formats\lib';
proc format library=library;
... ;
run;

, , Library.Formats SAS
Library,
C:\Sas\Formats\Lib.
LIB=
LIBRARY=.
proc format lib=library;

,
:
proc format lib=library.catalog;

, , , .

5.2 VALUE

5.2. VALUE

.
VALUE.

VALUE :
VALUE format-name
range1='label1'
range2='label2'
... ;
format-name

($)

,
VALUE
. , VALUE
JOBFMT
JobTitle.
proc format lib=library;
value jobfmt
103='manager'
105='text processor'
111='assoc. technical writer'
112='technical writer'
113='senior technical writer';
run;

5-5

5-6

VALUE

, 24 'S'
, 0-1500
, 'A'-'M'.
, ,
90,180,270 or 'B','D','F'.

,
,
($). ,
proc format lib=library;
value $grade
'A'='Good'
'B'-'D'='Fair'
'F'='Poor'
'I','U'='See Instructor';
run;

,

:
proc format lib=library;
value jobfmt
103='manager'
105='text processor'
111='assoc. technical writer'
112='technical writer'
113='senior technical writer';
run;

5.2 VALUE

VALUE

(<) .
proc format lib=library;
value agefmt
0-<12='child'
12-<20='teenager'
20-<65='adult'
65-100='senior citizen';
run;

LOW
HIGH .
OTHER:

proc format lib=library;


value agefmt
low-<12='child'
12-<20='teenager'
20-<65='adult'
65-high='senior citizen'
other='unknown';
run;

VALUE
FORMAT.,
VALUE :
proc format lib=library;
value jobfmt
103='manager'
105='text processor'
111='assoc. technical writer'
112='technical writer'
113='senior technical writer';
value $respnse
'Y'='Yes'
'N'='No'
'U'='Undecided'
'NOP'='No opinion';
run;

5-7

5-8

5.3.

, .
Work. ,
FMTSEARCH= :
Options fmtsearch=(libref1 libref2 . librefn);

libref1- librefn ,

FORMAT,
.
.
data perm.empinfo;
infile empdata;
input @9 FirstName $5. @1 LastName $7. +7 JobTitle 3.
@19 Salary comma9.;
format salary comma9.2 jobtitle jobfmt.;
run;

.

:
, ,
SAS .

.
Obs FirstName LastName JobTitle

Salary

1 Donny

Evans

technical writer

29,996.63

2 Lisa

Helms

text processor

18,567.23

3 John

Higgins

assoc. technical writer 25,309.00

4 Amy

Larson

senior technical writer 32,696.78

5 Mary

Moore

technical writer

28,945.89

6 Jason

Powell

manager

35,099.50

7 Judy

Riley

assoc. technical writer 25,309.00

8 Neal

Ryan

technical writer

9 Henry

Wilson

senior technical writer 31,875.46

Woods

text processor

10 Chip

28,180.00
17,098.71

5.3

(
VALUE),
:
proc format lib=library;
value jobfmt
103='manager'
105='text processor';
run;

Obs FirstName LastName JobTitle

Salary

Donny

Evans

112

29996.63

Lisa

Helms

text processor 18567.23

John

Higgins

111

25309.00

Amy

Larson

113

32696.78

Mary

Moore

112

28945.89

Jason

Powell

manager

35099.50

Judy

Riley

111

25309.00

,
, .

FMTLIB FORMAT:
libname library 'c:\sas\formats\lib';
proc format library=library fmtlib;
run;

Output
:

SAS Output
FORMAT NAME: JOBFMT LENGTH: 23 NUMBER OF VALUES: 5
MIN LENGTH: 1 MAX LENGTH: 40 DEFAULT LENGTH: 23 FUZZ: STD
START

END

LABEL

(VER. 8.00

103
105
111
112
113

103
105
111
112
113

manager
text processor
assoc. technical writer
technical writer
senior technical writer

24JUL99:14:50:28)

5-9

6.1 ..................................................................................................... 6-3


6.2 . 6-6
6.3 STOP POINT .. 6-15
6.4 .. 6-17
6.5 6-19

6-2

6.1

6.1.
SAS . ,
SAS .
, ,
(DATA step). ,

.


, , Lab23.Drug1H,
Research.CLTrials,
.
,
, CLTrials , , ,
Drug1H. ,
.

6-3

6-4

:
DATA SAS-data-set;
SET SAS-data-set;
RUN;

SAS-data-set DATA - (libref.filename)


SAS
SAS-data-set SET (libref.filename)
SAS .

, SAS
, ,
SET. DATA SAS
Drug1H, SAS,
Lab23. SET SAS
Research.CLTrials.
libname lab23 'c:\drug\allergy\labtests';
libname research 'c:\drug\allergy';
data lab23.drug1h;
set research.cltrials;
run;

, ,
.
, Log ,
, :
SAS Log
8
9
10

data lab23.drug1h;
set research.cltrials;
run;

NOTE: The data set LAB23.DRUG1H has 21


observations and 8 variables

,
Clinic.Stress2. , ,
. ,
.
, ,
.

6.1

...

...

if resthr<70 then delete;


if tolerance='D';

Drop timemin timesec;

TotalTime=(timemin*60)+timesec;

retain SumSec 5400;


sumsec+totaltime;

length TestLength $ 6;

if totaltime>800 then TestLength='Long';


else if 750<=totaltime<=800
then TestLength='Normal';
else if totaltime<=750
then TestLength='Short';

label sumsec='Cumulative Total Seconds';


format sumsec comma6.;

Research.CLTrials,
, .
data lab23.drug1h(drop=placebo uric);
set research.cltrials(drop=triglyc);
if sex='M' then delete;
if placebo='YES';
TestDate='22MAY1999'd;
retain Days 30;
days+1;
length Retest $ 5;
if cholesterol>190 then retest='YES';
else if 150<=cholesterol<=190 then retest='CHECK';
else if cholesterol<=150 then retest='NO';
label retest='Perform Cholesterol Test 2?';
format enddate mmddyy10.;
run;

6-5

6-6

6.2.
DROP= KEEP=
, DROP= KEEP=
SAS . , DROP= KEEP= ,
, , ,
. DROP= KEEP=
DATA SET, ,
:

,
, DROP=
SET.
, , DROP= SET
Triglycerides UricAcid.
Lab23.Drug1H.

data lab23.drug1h(drop=placebo);
set research.cltrials(drop=triglycerides uricacid);
if placebo='YES';
run;


(, IF),
DROP= DATA. ,
.
Placebo .
, Placebo , DROP=
DATA.

data lab23.drug1h(drop=placebo);
set research.cltrials(drop=triglycerides uricacid);
if placebo='YES';
run;

DATA, DROP=
.
,
.

6.2


Creating List Reports, BY PROC
SORT PROC PRINT
. BY
.
data temp;
set salary;
by dept;
run;

BY SET,

, SET,
,
.

BY
. FIRST.variable, variable
, LAST.variable.
1, 0. FIRST.variable LAST.variable
.
. . .

. . .
1

FIRST.variable

1

LAST.variable

FIRST.variable LAST.variable,
. Company.USA

6-7

6-8

. ,
. 2,000
- .
,
Dept.
SAS Company.USA
( )
Dept
ADM20
ADM30
CAM10
CAM10
CAM10
ADM30

WageCat

WageRate

S
S
S
S
H
S

3392.50
5093.75
1813.30
1572.50
13.48
2192.25


. , Dept FIRST. LAST.
proc sort data=company.usa out=work.temp;
by dept;
run;
data company.budget(keep=dept payroll);
set work.temp;
by dept;
if wagecat='S' then Yearly=wagerate*12;
else if wagecat='H' then Yearly=wagerate*2000;
if first.dept then Payroll=0;
payroll+yearly;
if last.dept;
run;

PDV (program data vector),


Company.Budget, .
FIRST.Dept LAST.Dept.

6.2

PDV
_N_

Dept

Payroll

FIRST.Dept

LAST.Dept

1
2
3
4
5

ADM10
ADM10
ADM10
ADM10
ADM10

70929.0
119479.2
173245.2
255516.0
293472.0

1
0
0
0
0

0
0
0
0
1

6
7
8
9
10

ADM20
ADM20
ADM20
ADM20
ADM20

40710.0
68010.0
94980.0
136020.0
177330.0

1
0
0
0
0

0
0
0
0
1

11

ADM30

61125.0

,
.
proc print data=company.budget noobs;
sum payroll;
format payroll dollar12.2;
run;

Dept

Payroll

ADM10

$293,472.00

ADM20

$177,330.00

ADM30

$173,388.00

CAM10

$130,709.60

CAM20

$156,731.20

$931,630.80

6-9

6-10


BY,

FIRST.variable 1


BY LAST.variable
1 BY .

,
. BY
, Manager JobType.
proc sort data=company.usa out=work.temp2;
by manager jobtype;
data company.budget2(keep=manager jobtype payroll);
set work.temp2;
by manager jobtype;
if wagecat='S' then Yearly=wagerate*12;
else if wagecat='H' then Yearly=wagerate*2000;
if first.jobtype then Payroll=0;
payroll+yearly;
if last.jobtype;
run;

PDV , . ,
FIRST.JobType LAST.JobType
FIRST.Manager LAST.Manager.
PDV
_N_ Manager JobType Payroll FIRST. LAST.
FIRST. LAST.
Manager Manager JobType JobType
1
2
3
4
5

Coxe
Coxe
Coxe
Coxe
Coxe

3
50
50
240
240

40710.0
41040.0
82350.0
27300.0
54270.0

1
0
0
0
0

0
0
0
0
1

1
1
0
1
0

1
0
1
0
1

6
7
8
9
10

Delgado
Delgado
Delgado
Delgado
Delgado

240
240
420
420
440

35520.0
63120.0
18870.0
45830.0
21759.6

1
0
0
0
0

0
0
0
0
1

1
0
1
0
1

0
1
0
1
1

11
12
13
14
15

Overby
Overby
Overby
Overby
Overby

1
5
10
20
20

82270.8
48550.2
53766.0
70929.0
108885.0

1
0
0
0
0

0
0
0
0
1

1
1
1
1
0

1
1
1
0
1

6.2


.
(Coxe Delgado).
proc print data=company.budget2 noobs;;
by manager;
var jobtype;
sum payroll;
where manager in ('Coxe','Delgado');
format payroll dollar12.2;
run;

Manager=Coxe
JobType

Payroll

$40,710.00

50

$123,390.00

240

$81,570.00

Manager $245,670.00
Manager=Delgado
JobType

Payroll

240

$98,640.00

420

$64,700.00

440

$21,759.00

Manager $185,099.00

6-11

6-12

, , ,
,
. ,
,
.
, ,
,
END= SET.

END=:
END=variable
variable ,
. , 0,
1, SET
.
.
Note:

END= POINT=. POINT=


, ,
.

,
. ,
,
TotalTime.
data work.addtoend(drop=timemin timesec);
set clinic.stress2(keep=timemin timesec);
TotalMin+timemin;
TotalSec+timesec;
TotalTime=totalmin*60+timesec;
run;
proc print data=work.addtoend noobs;
run;

6.2

TotalMin TotalSec TotalTime


12

38

758

22

43

1325

33

56

1993

42

98

2562

53

144

3226

65

170

3926

80

211

4841

93

224

5593

103

246

6202

119

295

7189

134

297

8042

146

308

8771

160

317

9609

171

343

10286

185

370

11127

198

389

11899

214

396

12847

231

431

13895

246

472

14801

260

529

15657

272

539

16330

, (
) ?
END= last .
END= SET last ,
( , IF).
data work.addtoend(drop=timemin timesec);
set clinic.stress2(keep=timemin timesec) end=last;
TotalMin+timemin;
TotalSec+timesec;
TotalTime=totalmin*60+timesec;
if last;
run;
proc print data=work.addtoend noobs;
run;

:
TotalMin TotalSec TotalTime
272

539

16330

6-13

6-14


. , ,
. ,
,
SAS ,
.
POINT= SET ,
.

POINT=:
POINT=variable;
variable

,
,
SET.

, .
, 5,
ObsNum. POINT= ObsNum ,
Company.USA.
data work.getobs5(drop=obsnum);
obsnum=5;
set company.usa(keep=manager payroll) point=obsnum;
run;

, ,
.

6.3 STOP POINT

6.3. STOP POINT


,
, .
, - , POINT=
, SAS ,
, . ,
.
data work.getobs5(drop=obsnum);
obsnum=5;
set company.usa(keep=manager payroll) point=obsnum;
run;

POINT=
- ,
,
:

STOP .
STOP SAS

.

,
POINT= variable. SAS
POINT= variable, _ERROR_
1.
, .

STOP:
STOP;

6-15

6-16

, STOP,
.
data work.getobs5(drop=obsnum);
obsnum=5;
set company.usa(keep=manager payroll) point=obsnum;
stop;
run;

- !
,
. ,
, STOP
.
, ,
.

6.4

6.4.

, -, ,
, OUTPUT
. OUTPUT
,
, OUTPUT.

OUTPUT:
OUTPUT <SAS-data-set(s)>;
SAS-data-set(s) ,
. , OUTPUT,
DATA.
OUTPUT
,
, DATA.

OUTPUT
5.
Data work.getobs5(drop=obsnum);
obsnum=5;
set company.usa(keep=manager payroll) point=obsnum;
output;
stop;
run;
proc print data=work.getobs5 noobs;
run;

Manager Payroll
Delgado

45830

6-17

6-18


, ,
, . , POINT=
. , POINT=
,
.
POINT=
DO Loop.


, ..
. SAS
. ,
SET , SAS
.

SET. ,
Finance.Loans, Interest
Finance.DueJan.
data finance.duejan;
set finance.loans;
Interest=amount*(rate/12);
run;

SAS Finance.Loans
Account

Amount

Rate

Months

Payment

101-1092
101-1731
101-1289
101-3144

22000
114000
10000
3500

0.1000
0.0950
0.1050
0.1050

60
360
36
12

467.43
958.57
325.02
308.52

6.5

6.5.

1. (PDV),
_N_ _ERROR_.

2. SAS
.
3. SET , PDV
.
, , , ,
.

4. , ,
PDV. ,
.

5. , ,
SAS . , ..
.
, .

6-19

6-20


1.
. ,
, .. Finance.Loans
.
2. , _N_ 1.
, _ERROR_ 0.
.
,
.

6.5

3. SET
PDV.

4. ,
Interest.

6-21

6-22

()
5. , PDV
.

6. .

6.5

7. SAS , SAS
SET,
. ,
, Interest, .

NOTE:

SAS e, .
, SAS
,
:

, RETAIN
,
, _TEMPORARY_
,
FILE INFILE
.

6-23

6-24

()
8. , _N_ 2,
_ERROR_ 0. ,
_N_ ,
.

6.5

9. SET,
PDV.

10.
Interest .

6-25

6-26


. ,

IF-THEN/ELSE DO
DO loops ,



SAS .

SAS ,
, , ,
, .

7.1 ........................................................................................ 7-3


7.2 ....................................................................................... 7-6

7-2

7.1

7.1.
.

SAS
.

Log-
.


.. (Input Buffer)
.
( SAS
).

(Program Data Vector)


(program data
vector). , SAS
.

7-3

7-4


, ,
.
_N_
_ERROR_
( ). 0,
, 1
.

,
.
,
.
Item
( 13 ), IDnum ( 5 ) InStock, BackOrd Total
( 8 ).
data perm.update;
infile invent;
input Item $ 1-13 IDnum $ 15-19
InStock 21-22 BackOrd 24-25;
Total=instock+backord;
run;

(
RUN) (descriptor portion).




( ,
..)

7.1

7-5

Data Set Name:


Member Type:
Engine:
Created:
Last Modified:
Protection:
Data Set Type:
Label:

PERM.UPDATE
DATA
V8
14:38 Thursday, July 27, 2000
14:38 Thursday, July 27, 2000

Observations:
Variables:
Indexes:
Observation Length:
Deleted Observations:
Compressed:
Sorted:

-----Engine/Host Dependent Information----Data Set Page Size:


Number of Data Set Pages:
First Data Page:
Max Obs per Page:
Obs in First Data Page:
Number of Data Set Repairs:
File Name:
Release Created:
Host Created:

4096
1
1
84
9
0
C:\WINNT\My SAS Files\V8\update.sas7bdat
8.0202M0
WIN_NT

-----Alphabetic List of Variables and Attributes----#


Variable
Type
Len
Pos
----------------------------------4
BackOrd
Num
8
8
2
IDnum
Char
5
37
3
InStock
Num
8
0
1
Item
Char
13
24
5
Total
Num
8
16

9
5
0
48
0
NO
NO

7-6

7.2.
, .
(data portion).

,
.
.

7.2

Invent
9 , .
Invent
>----+----10---+----20---+Bird Feeder
LG088 3 20
6 Glass Mugs SB082 6 12
Glass Tray
BQ049 12 6
Padded Hangrs MN256 15 20
Jewelry Box
AJ498 23 0
Red Apron
AQ072 9 12
Crystal Vase AQ672 27 0
Picnic Basket LS930 21 0
Brass Clock
AN910 2 10

data perm.update;
infile invent;
input Item $ 1-13 IDnum $ 15-19
InStock 21-22 BackOrd 24-25;
Total=instock+backord;
run;


_N_ 1,
_ERROR_ 0. ,
(missing) (
, ).
data perm.update;
infile invent;
input Item $ 1-13 IDnum $ 15-19
InStock 21-22 BackOrd 24-25;
Total=instock+backord;
run;

7-7

7-8


(INFILE)
.
INPUT. INPUT
(input pointer)

. , 1,
1 13
Item.

data perm.update;
infile invent;
input Item $ 1-13 IDnum $ 15-19
InStock 21-22 BackOrd 24-25;
Total=instock+backord;
run;

Raw Data File Invent


>V---+----10---+----20---+Bird Feeder
LG088 3 20
6 Glass Mugs SB082 6 12
Glass Tray
BQ049 12 6
Padded Hangrs MN256 15 20
Jewelry Box
AJ498 23 0
Red Apron
AQ072 9 12
Crystal Vase AQ672 27 0
Picnic Basket LS930 21 0
Brass Clock
AN910 2 10

, ,
Total .
data perm.update;
infile invent;
input Item $ 1-13 IDnum $ 15-19
InStock 21-22 BackOrd 24-25;
Total=instock+backord;
run;

7.2

Raw Data File Invent


>----+----10---+----20---+V
Bird Feeder
LG088 3 20
6 Glass Mugs SB082 6 12
Glass Tray
BQ049 12 6
Padded Hangrs MN256 15 20
Jewelry Box
AJ498 23 0
Red Apron
AQ072 9 12
Crystal Vase AQ672 27 0
Picnic Basket LS930 21 0
Brass Clock
AN910 2 10

(
)

,
.
_N_ _ERROR_ .

,
.

7-9

8
SQL

8.1 SQL ............................................................................ 8-3


8.2 SQL .................................................................... 8-6
8.3 ..................................... 8-11
8.4 .................................................................... 8-15
8.5 ....................................................... 8-17

8-2

8 SQL

8.1 SQL

8.1. SQL
PROC SQL SAS
(SQL), , ,
, ,
.
, ,
, SAS SQL.

SAS

SQL

SAS

PROC SQL ,

SAS

,

.

PROC SQL
, .
, PROC SQL
. ,
. ,
SAS .

8-3

8-4

8 PROC SQL

PROC SQL
PROC SQL SAS
:
PROC, PROC SQL
. ,
. PROC SQL. ,
SELECT (, FROM, WHERE
ORDER BY).
proc sql;
select id,lastname,netpay,grosspay,
grosspay*.06 as bonus
from emplib.payroll
where netpay>25000

order by lastname;

PROC SQL RUN.


PROC SQL .
PROC SQL RUN,
SAS RUN,
SAS log, .

PROC SQL,
Program Editor PROC SQL
running. ,
SQL ,
.

8.1 SQL


, QUIT ( ).
quit;

8-5

8-6

8 PROC SQL

8.2. SQL
, , , ,
, . , PROC SQL,
.

PROC SQL:
PROC SQL;
SELECT column-1<, . . . column-n,>
FROM table-1 | view-1<, . . . table-n | view-n>
<WHERE expression>
<ORDER BY column-1<, . . . column-n,>>;

PROC SQL SQL


SELECT
FROM
WHERE ,

ORDER BY .

,
SQL SELECT .

8.2 SQL

SELECT
SELECT .
,
. SELECT ,
, : SELECT, FROM, WHERE
ORDER BY. .
proc sql;
|-select id,lastname,netpay,grosspay,
|
grosspay*.06 as bonus
|----from emplib.payroll
|----where netpay>25000
|----order by lastname;
^

, :
proc sql;
select id,lastname,netpay,grosspay,
grosspay*.06 as bonus
from emplib.payroll
where netpay>25000
order by lastname;

ID

LastName

NetPay GrossPay bonus

1002 BOWMAN

$29,048.50

$42,120.33

2527.22

1007 BROWN

$37,049.40

$53,927.72 3235.663

1049 FERNANDEZ

$25,169.63

$35,956.61 2157.397

1006 GARRETT

$34,013.88

$47,241.50

1077 GIBSON

$41,553.94

$61,108.73 3666.524

1008 HERNAND

$54,189.70

$78,575.07 4714.504

1009 JONES

$44,128.90

$63,986.91 3839.215

1005 KNAPP

$33,122.70

$48,027.99 2881.679

1012 QUINTERO

$51,888.53

$79,828.51 4789.711

1015 SCHOLL

$27,640.80

$40,079.23 2404.754

1010 SMITH

$37,331.48

$54,899.24 3293.954

1011 VAN HOTTEN

$29,053.05

$43,688.80 2621.328

1017 WAGGONNER $26,484.02

$38,550.25 2313.015

1001 WATERHOUSE $32,140.60

$46,603.94 2796.236

2834.49

8-7

8-8

8 PROC SQL


PROC SQL, SELECT ,
, .
SELECT ,
. SELECT, , ID,
LastName, NetPay, GrossPay bonus.

proc sql;
select id,lastname,netpay,grosspay,
grosspay*.06 as bonus
from emplib.payroll
where netpay>25000
order by lastname;


bonus ,
GrossPay 0.6.
AS, .
proc sql;
select id,lastname,netpay,grosspay,
grosspay*.06 as bonus
from emplib.payroll
where netpay>25000
order by lastname;

, bonus , ,
SELECT.

ID

LastName

NetPay GrossPay

bonus

1002

BOWMAN

$29,048.50

$42,120.33

2527.22

1007

BROWN

$37,049.40

$53,927.72

3235.663

1049

FERNANDEZ $25,169.63

$35,956.61

2157.397

1006

GARRETT

$34,013.88

$47,241.50

2834.49

1077

GIBSON

$41,553.94

$61,108.73

3666.524

1008

HERNAND

$54,189.70

$78,575.07

4714.504

1009

JONES

$44,128.90

$63,986.91

3839.215

1005

KNAPP

$33,122.70

$48,027.99

2881.679

1012

QUINTERO

$51,888.53

$79,828.51

4789.711

8.2 SQL


SELECT, FROM
, .
FROM, SAS .
proc sql;
select id,lastname,netpay,grosspay,
grosspay*.06 as bonus
from emplib.payroll
where netpay>25000
order by lastname;

PROC SQL, , SAS Payroll,


SAS , libref
(Emplib).

, ,
WHERE SELECT. WHERE
WHERE, WHERE
SAS .
proc sql;
select id,lastname,netpay,grosspay,
grosspay*.06 as bonus
from emplib.payroll
where netpay>25000
order by lastname;

WHERE , NetPay
, 25,000.

ID

LastName

NetPay GrossPay

bonus

1002

BOWMAN

$29,048.50

$42,120.33

2527.22

1007

BROWN

$37,049.40

$53,927.72

3235.663

1049

FERNANDEZ $25,169.63

$35,956.61

2157.397

1006

GARRETT

$34,013.88

$47,241.50

2834.49

1077

GIBSON

$41,553.94

$61,108.73

3666.524

1008

HERNAND

$54,189.70

$78,575.07

4714.504

1009

JONES

$44,128.90

$63,986.91

3839.215

1005

KNAPP

$33,122.70

$48,027.99

2881.679

1012

QUINTERO

$51,888.53

$79,828.51

4789.711

8-9

8-10

8 PROC SQL



.
ORDER BY SELECT,
.
ORDER BY PROC SQL
, Sex Age.
proc sql;
select actlevel,sex,age,
height*2.54 as CentHgt,
weight/2.2 as KgWgt
from clinic.admit
where actlevel='LOW'
order by sex,age;

ActLevel Sex Age CentHgt KgWgt


LOW

22

160.02 63.18182

LOW

28

157.48 53.63636

LOW

31

154.94 55.90909

LOW

49

162.56 78.18182

LOW

34

185.42

LOW

51

180.34 71.81818

LOW

60

180.34 86.81818

70

8.3

8.3.
, PROC SQL, .
, ,
. SQL, .
, ,
, , .
.
, , ,
. ,
, ,
, .

.
,
. (
,
.)
, , PROC SQL
. ,
PROC SQL , .
Payroll BldgInfo, SAS ,
libref Emplib.
proc sql;
select bldginfo.id,lastname,building,room,extension
from emplib.payroll,emplib.bldginfo
where bldginfo.id=payroll.id
order by lastname;

8-11

8-12

8 PROC SQL

,
,
SELECT, , ,
.
SELECT, , SELECT
BldgInfo ID. ID
. ,
.
proc sql;
select bldginfo.id,lastname,building,room,extension
from emplib.payroll,emplib.bldginfo
where bldginfo.id=payroll.id
order by lastname;

ID EmpLib.BldgInfo. ,
, .
.


,
FROM , .
proc sql;
select bldginfo.id,lastname,building,room,extension
from emplib.payroll,emplib.bldginfo
where bldginfo.id=payroll.id
order by lastname;

, SELECT, FROM
.

8.3


, WHERE SELECT
.
,
WHERE, .
, WHERE ,
ID. ( WHERE
, SELECT.)
proc sql;
select bldginfo.id,lastname,building,room,extension
from emplib.payroll,emplib.bldginfo
where bldginfo.id=payroll.id
order by lastname;

ID

LastName

Building Room Extension

1002 BOWMAN

34

2782

1007 BROWN

48

0342

1049 FERNANDEZ

22

1347

1006 GARRETT

16

2209

1077 GIBSON

17

1697

1008 HERNAND

19

6391

1009 JONES

24

3857

1005 KNAPP

98

5917

1004 KNIGHT

13

6718

1074 MILLSAP

56

1543

1012 QUINTERO

30

7518

1003 SALAZAR

65

2771

1083 SAVAGE

22

7357

1015 SCHOLL

49

3756

1010 SMITH

37

2134

1011 VAN HOTTEN

51

2649

1017 WAGGONNER C

26

2719

1001 WATERHOUSE A

57

2345

, ,
.

8-13

8-14

8 PROC SQL


ORDER BY SELECT
.
proc sql;
select bldginfo.id,lastname,building,room,extension
from emplib.payroll,emplib.bldginfo
where bldginfo.id=payroll.id
order by lastname;

,
LastName.
ID

LastName

Building Room Extension

1002

BOWMAN

34

2782

1007

BROWN

48

0342

1049

FERNANDEZ

22

1347

1006

GARRETT

16

2209

1077

GIBSON

17

1697

1008

HERNAND

19

6391

1009

JONES

24

3857

1005

KNAPP

98

5917

1004

KNIGHT

13

6718

1074

MILLSAP

56

1543

1012

QUINTERO

30

7518

1003

SALAZAR

65

2771

1083

SAVAGE

22

7357

1015

SCHOLL

49

3756

1010

SMITH

37

2134

1011

VAN HOTTEN

51

2649

1017

WAGGONNER C

26

2719

1001

WATERHOUSE A

57

2345

8.4

8.4.
PROC SQL -.
.
GROUP
BY. GROUP BY ,
.
,
GROUP BY.

,
Master.Salaries.
.
proc sql;
select dept as Department,
sum(wagerate) as TotalWages
from master.salaries
group by dept;

WageRate,
TotalWages. GROUP BY
Department.
ORDER BY,
.
.
Department TotalWages
ADM10

14939.6

ADM20

43407.47

ADM30

8652.35

ADM40

78874.07

CAM10

5726.34

CAM20

5516.95

CAM30

8834.55

CAM32

200.34

CAM34

158.18

CAM36

171.84

LAM10

12271.07

LAM20

2807.4

LAM32

117.96

LAM34

102.88

LAM36

117.08

8-15

8-16

8 PROC SQL

GROUP BY
,
ORDER BY, SAS log.


PROC SQL. , ,
SAS SQL
AVG, MEAN
COUNT, FREQ, N
CSS
CV
MAX
MIN
NMISS
PRT
RANGE
STD
STDERR
SUM




()



( )



8.5

8.5.
CREATE
TABLE PROC SQL.
SAS , .

PROS SQL :
PROC SQL;
CREATE TABLE table-name AS
SELECT column-1<, . . . column-n,>
FROM table-1 | view-1<, . . . table-n | view-n>
<WHERE expression>
<ORDER BY column-1<, . . . column-n,>>;
table-name .

,
Master.Salaries,
Master.Wages. PROC SQL:
proc sql;
create table master.wages as
select dept as Department,
sum(wagerate) as TotalWages
from master.salaries
group by dept;

. SAS log ,
, .


SELECT. ,
GROUP BY,
HAVING ,
, .
proc sql;
select custname as name, count(*)
from sql.customer
group by name
having count(*)=1;

8-17

9.1 ................................................................................ 9-3


9.2 ........................................................................ 9-5
9.3 ............................................................................... 9-8
9.4 .............................................................................................. 9-10
9.5 .................................................. 9-12
9.6 .................................................................. 9-20
9.7 .............................................. 9-23

9-2

9.1

9.1.

SAS
. ,
, :



,


.


.
: SET



.
: SET

9-3

9-4


,

.
: SET, BY






.
: MERGE, BY

PROC SQL
.

9.2

9.2.
SAS
SET.
SET .
. ,
,
, .

:
DATA output-SAS-data-set;
SET SAS-data-set-1;
SET SAS-data-set-2;
RUN;

output-SAS-data-set
SAS-data-set-1 SAS-data-set-2 .

SET.


.
, ,
, ,
.

-
.

; ,
..
,
.
data one2one;
set c;
set d;
run;

9-5

9-6


.
data one2one;
set c;
set d;
run;

1. SET C.
Num

VarA

A1

VarB

2. , SET D.
Num D
Num C.
Num

VarA

VarB

A1

B1

9.2

3. . ,
SET C.
Num

VarA

VarB

A1

B1

A2

4. , SET
D, Num C.
,
.
C.
Num

VarA

VarB

A1

B1

A2

B2

9-7

9-8

9.3.
SAS SET -
,
. SAS ,
SET.

:
DATA output-SAS-data-set;
SET SAS-data-set-1 SAS-data-set-2;
RUN;

output-SAS-data-set
SAS-data-set-1 SAS-data-set-2
.


,
, SET. ,
, ,
.
.

data concat;
set a b;
run;

9.3

9-9

9-10

9.4.

BY, ,
.
, .
SAS
SET, BY.

:
DATA output-SAS-data-set;
SET SAS-data-set-1 SAS-data-set-2;
BY variable(s);
RUN;

output-SAS-data-set
SAS-data-set-1 SAS-data-set-2

variable(s) ,
.

SET.

BY.

9.4


SAS System ,
SET ,
, ,
, .

.
data interlv;
set c d;
by num;
run;

9-11

9-12

9.5.

. ,

.
.

MERGE, SET.


:
DATA output-SAS-data-set;
MERGE SAS-data-set-1 SAS-data-set-2;
BY variable(s);
RUN;

output-SAS-data-set
SAS-data-set-1 SAS-data-set-2
variable(s) BY ,
.

50 MERGE.

.
.

9.5


, , SAS

, ,
.
data merged;
merge a b;
by num;

run;


,
. (
,
.)

,
.

,
,
.

9-13

9-14


.
,
, .
, ,
.
, :

, SAS
( ). , SAS

(program data vector - PDV), , SAS
, .

,
.
,
PDV.
.

9.5

:
, SAS
1. ,
MERGE
2.
3. (PDV) 3
4. MERGE
.
,
(
MERGE) .


. Clients Amounts,
SAS
1. PDV Claims.
. ,
Name , PDV
.
2. Clients Amounts.

9-15

9-16

:
, SAS
,
, , .

, PDV ,
MERGE.

. SAS

PDV, BY
.

, SAS ,
, , PDV. , PDV
.

9.5

BY ,
PDV .


,
.

9-17

9-18


, , PDV,
. ( IF
, ,
IF.)

,

. ,
BY,
.

9.5

BY,

,
.

9-19

9-20

9.6.
,
. ,
PDV PDV
.
, Clinic.Demog Date ( ), Clinic.Visit
Date ( 1998). ,
, .
data clinic.merged;
merge clinic.demog clinic.visit;
by id;
run;
proc print data=clinic.merged;
run;


Clinic.Merged.
. 11, - , ..
Clinic.Visit ID .

Obs ID Age Sex

Date Visit SysBP DiasBP Weight

1 A001

21 m

11/05/98 1

140

85

195

2 A001

21 m

10/13/98 2

138

90

198

3 A001

21 m

07/04/98 3

145

95

200

4 A002

32 m

04/14/98 1

121

75

168

5 A003

24 f

08/12/98 1

118

68

125

6 A003

24 f

08/21/98 2

112

65

123

7 A004

03/30/98 1

143

86

204

8 A005

44 f

02/27/98 1

132

76

174

9 A005

44 f

07/11/98 2

132

78

175

10 A005

44 f

04/16/98 3

134

78

176

11 A007

39 m

11/11/57

12 A008

126

80

182

05/22/98 1

Date,
: . ,
.

9.6

,
, RENAME= MERGE.

RENAME=:
(RENAME=(old-variable-name=new-variable-name))

RENAME=, ,
,

old-variable-name ,
new-variable-name .


RENAME=.
RENAME=
SET ,
DATA.

9-21

9-22

, RENAME= Date
Clinic.Demog BirthDate, Date Clinic.Visit VisitDate.
data clinic.merged;
merge clinic.demog(rename=(date=BirthDate))
clinic.visit(rename=(date=VisitDate));
by id;
run;
proc print data=clinic.merged;
run;

RENAME=.

Obs ID Age Sex BirthDate Visit SysBP DiasBP Weight VisitDate


1 A001

21 m

05/22/75 1

140

85

195

11/05/98

2 A001

21 m

05/22/75 2

138

90

198

10/13/98

3 A001

21 m

05/22/75 3

145

95

200

07/04/98

4 A002

32 m

06/15/63 1

121

75

168

04/14/98

5 A003

24 f

08/17/72 1

118

68

125

08/12/98

6 A003

24 f

08/17/72 2

112

65

123

08/21/98

7 A004

03/27/69 1

143

86

204

03/30/98

8 A005

44 f

02/24/52 1

132

76

174

02/27/98

9 A005

44 f

02/24/52 2

132

78

175

07/11/98

10 A005

44 f

02/24/52 3

134

78

176

04/16/98

11 A007

39 m

11/11/57

12 A008

126

80

182

05/22/98

. 1

9.7

9.7.
,
. ,
.


, IN= IF
. ,

IN= ,
,

IF IN=variable
,
, IN=.

IN=
,
Clinic.Demog Clinic.Visit ,
.
-, IN= ,
indemog invisit. IN= variable ,
,
SAS .

9-23

9-24

IN=:
(IN=variable)

IN= , ,
variable .

, 1,
. , = 0.

, IN= , . IN=
indemog, 1,
Clinic.Demog; , 0. ,
invisit , Clinic.Visit .
data clinic.merged;
merge clinic.demog(in=indemog)
clinic.visit(in=invisit
rename=(date=BirthDate));
by id;
run;



, Clinic.Demog
Clinic.Visit, IF .
, , IF indemog
invisit ,
. ,
Clinic.Demog Clinic.Visit .
, Clinic.Merged.
, .

9.7

data clinic.merged;
merge clinic.demog(in=indemog
rename=(date=BirthDate))
clinic.visit(in=invisit
rename=(date=VisitDate));
by id;
if indemog=1 and invisit=1;
run;
proc print data=clinic.merged;
run;

, Clinic.Merged 12 .
10 , IF.
Obs ID Age Sex BirthDate Visit SysBP DiasBP Weight VisitDate
1 A001

21 m

05/22/75 1

140

85

195

11/05/98

2 A001

21 m

05/22/75 2

138

90

198

10/13/98

3 A001

21 m

05/22/75 3

145

95

200

07/04/98

4 A002

32 m

06/15/63 1

121

75

168

04/14/98

5 A003

24 f

08/17/72 1

118

68

125

08/12/98

6 A003

24 f

08/17/72 2

112

65

123

08/21/98

7 A004

03/27/69 1

143

86

204

03/30/98

8 A005

44 f

02/24/52 1

132

76

174

02/27/98

9 A005

44 f

02/24/52 2

132

78

175

07/11/98

10 A005

44 f

02/24/52 3

134

78

176

04/16/98

SAS IF ,
, .
, ,
.
, IF
. IF
1. IF ,
, 0 ( IN= variable
1).
if indemog=1 and invisit=1;
if indemog and invisit;

9-25

9-26

SAS
, ,
DROP= KEEP=.
, , ,
Clinic.Demog , Weight, Clinic.Visit. ,
ID Clinic.Merged
.
data clinic.merged(drop=id);
merge clinic.demog(in=indemog
rename=(date=BirthDate))
clinic.visit(drop=weight in=invisit
rename=(date=VisitDate));
by id;
if indemog and invisit;
run;
proc print data=clinic.merged;
run;

Obs Age Sex BirthDate Visit SysBP DiasBP VisitDate


1

21 m

05/22/75 1

140

85

11/05/98

21 m

05/22/75 2

138

90

10/13/98

21 m

05/22/75 3

145

95

07/04/98

32 m

06/15/63 1

121

75

04/14/98

24 f

08/17/72 1

118

68

08/12/98

24 f

08/17/72 2

112

65

08/21/98

03/27/69 1

143

86

03/30/98

44 f

02/24/52 1

132

76

02/27/98

44 f

02/24/52 2

132

78

07/11/98

10

44 f

02/24/52 3

134

78

04/16/98

9.7

9-27

DROP= KEEP=
DROP= KEEP= SAS
. ,
DATA MERGE,
,
:

,
,
DROP= MERGE.
merge clinic.demog(in=indemog
rename=(date=BirthDate))
clinic.visit(drop=weight in=invisit
rename=(date=VisitDate));


(, IF),
DROP= DATA. , ,
,
.
data clinic.merged(drop=id);

DROP= DATA,
.

.


. ,

IF-THEN/ELSE





SAS
, FIRST. LAST.
.

9-28


. ,

IF-THEN/ELSE





SAS
, FIRST. LAST.
.

SAS :

--, ,
.

.
-- --,
:
o

MERGE SET.

.
data work.onemerge;
merge clinic.demog clinic.visit;
run;

, DO
:
data work.combine;
set sales.pounds;
do while(not(begin le date le last));
set sales.rate;
end;
Dollars=(sales*1000)*rate;
run;

SET:
data work.combine(drop=totpay);
if _n_=1 then do until(last);
set sales.budget(keep=payroll) end=last;
end;
set sales.budget;
Percent=payroll/totpay;
run;

10

10.1 .......................................... 10-3


10.2
PROC UNIVARIATE ............................................................................... 10-12
10.3 MEANS ...................... 10-15
10.4
FREQ .................................................................................... 10-18
10.5 CORR .................................... 10-20
10.6 PROC REG
.................................................................................................... 10-22
10.7 ANOVA
........................................................................ 10-26

10-2

10

10.1

10-3

10.1.
SAS BASE
:
CORR
.
MEANS SUMMARY .
.
TABULATE ,
.
UNIVARIATE
.
CHART , , ,
, .
FREQ ,
-, ,
.

.

MEANS

UNIVARIATE

SUMMARY

TABULATE

CORR

-
Prob>| t |

10-4

10

MEANS


CLASS
BY

UNIVARIATE

SUMMARY

TABULATE

CORR

, ,
. , PROC UNIVARIATE

. PROC UNIVARIATE , ,
.
,
BY. , BY
,
. SUMMARY MEANS TABULATE
(
) CLASS.


,
.
xi

i- ()

wi

, xi ,
WEIGHT, - 1

wi xi / wi

n
x

, VARDEF=N
, VARDEF=DF
, VARDEF=WEIGHT | WGT

n
n 1
wi

( w ) 1
w (x x )

, VARDEF=WDF

s2
zi

( xi x ) / s

/d

()

10.1

10-5

,
.
N
NMISS
MIN
MAX
:
SUM

() .
.
.
.
MAX MIN, ().
wi xi .

SUMWGT

MEAN
USS

x .
wi xi2 .

CSS

w (x

VAR
COVARIANCE

s 2 (, variance).
cov xy wi ( xi x )( y i y ) / d .

STD
STDERR

s .
s / n .
100% s / x .

CV
SKEWNESS
KURTOSIS
T
PRT

MEDIAN
QUARTILE
MODE

x ) 2 .

.
(n 1)(n 2)

n(n + 1)
3(n 1) 2
z i3 (n 1)(n 2)(n 3) (n 2)(n 3) .

3
i

t = x n / s H0( =0).
n 1 ,
H0 t value
t value . Pr ob > t .
xi , n ,
, n .
, xi ,
, xi .
.

10-6

10


, ,
. N NMISS
. SUM, MEAN, MAX, MIN, :, USS CSS
.
:

VAR, STD, STDERR, CV, T PRT .


SKEWNESS .
KURTOSIS .
SKEWNESS, KURTOSIS, T PRT , STD 0.
CV , MEAN 0.


(population),
, , . (population)
- .
- ..
.
, :
.
.
, (distribution)
.
()
, .
, ,
.
.


, , .
(sample).
.
, ,
, ,
, (estimates) .
() ,
.

10.1

10-7


, ,
.
, 25%
75% :
(mean) = E (x) x = xi / n
(median) ,
.
,
.
(mode) , .
.
(percentiles) (quantiles)
. , ,
,
. .. 25% 75% .
options formchar='|- +++';
title 'Example of Quantiles and Measures of Location';
data random;
drop n;
do n=1 to 1000;
x=floor(exp(rannor(314159)*.8+1.8));
output;
end;
run;
proc univariate;
var x;
output
out=location mean=mean mode=mode median=median
q1=q1 q3=q3 p5=p5 p10=p10 p90=p90 p95=p95 max=max;
run;
proc print;
run;
data _null_;
set location;
call symput ('MEAN', round(mean,1));
call symput ('MODE', mode);
call symput ('MEDIAN', round(median,1));
call symput ('Q1', round(q1,1));
call symput ('Q3', round(q3,1));
call symput ('P5', round(p5,1));
call symput ('P10', round(p10,1));
call symput ('P90', round(p90,1));
call symput ('P95', round(p95,1));
call symput ('MAX', min(50,MAX));
run;
%macro formgen;
%do i=1 %to &max;
%let value=&i;
%if &i=&p5
%then %let value=&value
p5;
%if &i=&p10
%then %let value=&value
p10;
%if &i=&q1
%then %let value=&value
q1;
%if &i=&mode
%then %let value=&value
mode;
%if &i=&median
%then %let value=&value
median;
%if &i=&mean
%then %let value=&value
mean;
%if &i=&q3
%then %let value=&value
q3;

10-8

10

%if &i=&p90
%if &i=&p95
%if &i=&max
&i="&value"

%then %let value=&value


%then %let value=&value
%then %let value=>=&value;

p90;
p95;

%end;
%mend;
proc format print;
value stat %formgen;
run;
proc chart data=random;
vbar x / midpoints=1 to &max by 1;
format x stat.;
footnote 'P5 = 5TH PERCENTILE';
footnote2 'P10 = 10TH PERCENTILE';
footnote3 'P90 = 90TH PERCENTILE';
footnote4 'P95 = 95TH PERCENTILE';
footnote5 'Q1 =
1ST QARTILE';
footnote6 'Q3 =
3RD QARTILE';
run;
Example of Quantiles and Measures of Location
The UNIVARIATE Procedure
Variable: x
N
Mean
Std Deviation
Skewness
Uncorrected SS
Coeff Variation

Moments
1000
Sum Weights
5.605
Sum Observations
5.38169794
Variance
2.73038523
Kurtosis
112271
Corrected SS
95.0637467
Std Error Mean

1000
7605
54.4894645
11.1870588
54434.975
0.23342978

Basic Statistical Measures


Location
Variability
Mean
5.605000
Std Deviation
5.38170
Median
5.000000
Variance
54.48946
Mode
3.000000
:
62.00000
Interquartile :
6.00000
Tests for Location: Mu0=0
Test
-Statistic-----p Value-----Student's t
t 32.57939
Pr > |t|
<.0001
Sign
M
494.5
Pr >= |M|
<.0001
Signed Rank
S 244775.5
Pr >= |S|
<.0001
Quantiles (Definition 5)
Quantile
Estimate
100% Max
62.0
99%
35.5
95%
21.5
90%
16.0
75% Q3
9.0
50% Median
5.0
25% Q1
3.0
10%
2.0
5%
1.0
1%
0.0
0% Min
0.0
Extreme Observations
----Lowest-------Highest--Value
Obs
Value
Obs
0
941
44
216
0
756
44
486
0
402
57
319
0
358
61
951
0
323
62
147

10.1
Obs

mean
1

max
5.605

p95
62

p90
21.5

q3
16

median
9

q1

p10
5

p5
3

10-9

mode
2

Frequency
120 + *
| *
| **
| ***
90 +*****
|*****
|*******
|*******
60 +*******
|*********
|*********
|*********
30 +************
|************
*
|**************** *
|*********************** * *
-------------------------------------------------1234567891111111111222222222233333333334444444444>
0123456789012345678901234567890123456789=
P5
P10
P90
P95
Q1
Q3

x Midpoint
= 5TH PERCENTILE
= 10TH PERCENTILE
= 90TH PERCENTILE
= 95TH PERCENTILE
=
1ST QARTILE
=
3RD QARTILE



:
(:)
.
(interquarile :) 25%
75% .
(variance) 2 = E ( x ) 2 ,
s 2 = ( xi x ) /(n 1) .
2

, .. .
(standard deviation) s -
.

. -
.


, :
(skewness) E ( x ) 3 / 3 ,
3

n
n

( xi x ) / s 3
(n 1)(n 2) i =1
(kurtosis) E ( x ) 4 / 4 3 ,
4

n
n(n + 1)
(n 1) 2
4
(
x

x
)
/
s

3
i
(n 1)(n 2)(n 3) i =1
(n 2)(n 3)

10-10

10



. :
.

.
68%
, 95% , 99%
.


n ,
, , ,
(sampling distribution). ,
:
.
, (standard error)
/ n s / n - .


( )
,
.

- . ,
, (). : H 0 : = 0, H 1 : < 0, H 2 : > 0 . ,
:

(significance level)

(power).
, , 2 - 95%
3 - 99%, , H 0 : = 0, H 1 : < 0, H 2 : > 0 , 0 2 x 0 + 2 ,
95% H 0 : = 0 ,
.
, , ,
s . ,
t = ( x 0 ) /( s / n ) ,
x 0 . t
0. t ,
0
. , =5%
n 1 = 8 2,3 2,3.

10.1

10-11


p value . ,
t
. ,
p value ,
[ ( p value) > t ] < , .



, :
.
.
.

10-12

10

10.2. PROC
UNIVARIATE

, - ,
. ,
, ,
.
, ,
PROC UNIVARIATE.
PROC UNIVARIATE SAS BASE,
. , ,
, , ..
PROC UNIVARIATE . PROC,
,
, VAR:
PROC UNIVARIATE;
VAR variable-list;

VAR,
, .
DATA=input data set PROC.
PROC UNIVARIATE DATA=data set;

, PROC , ,
PLOT NORMAL.
PROC UNIVARIATE PLOT NORMAL;

NORMAL , PLOT
, , : --,
-- (steam-and-leaf, boxand-whisker, normal probability).
,
, BY
( , ,
). ,
, .
UNIVARIATE.

10.2 PROC UNIVARIATE

10-13

UNIVARIATE
PROC UNIVARIATE <option(s)>;
BY <DESCENDING> variable-1 <...<DESCENDING> variable-n> <NOTSORTED>;
CLASS variable-1<(variable-option(s))> <variable-2<(variableoption(s))>> </KEYLEVEL= 'value1'|('value1' 'value2')>;
FREQ variable;
HISTOGRAM <variable(s)> </ option(s)>;
ID variable(s);
INSET <keyword(s)> </ option(s)>;
OUTPUT <OUT=SAS-data-set> statistic-keyword-1=name(s) <... statistickeyword-n=name(s)> <percentiles-specification>;
PROBPLOT <variable(s)> </ option(s)>;
QQPLOT <variable(s)> </ option(s)>;
VAR variable(s);
WEIGHT variable;



.
Data Class;
input Student
cards;
A 56 1 B 78 1 C 84
A 85 2 B 67 2 C 90
A 87 3 B 73 3 C 99
;
run;

$1. Score Course +1 @@;


1
2
3

D 73 1
D 84 2
D 54 3

E 90 1
E 74 2
E 81 3

F 44 1
F 64 2
F 78 3

G 76 1
G 73 2
G 69 3

H 87 1
H 78 2
H 64 3

I 92 1
I 69 2
I 73 3

proc univariate data = class plot normal;


var score;
title;
run;
The UNIVARIATE Procedure
Variable: Score
N
Mean
Std Deviation
Skewness
Uncorrected SS
Coeff Variation

Moments
30
Sum Weights
74.6
Sum Observations
12.5164719
Variance
-0.3816614
Kurtosis
171498
Corrected SS
16.7781125
Std Error Mean

Basic Statistical Measures


Location
Variability
Mean
74.60000
Std Deviation
Median
74.50000
Variance
Mode
73.00000
Range
Interquartile Range

30
2238
156.662069
0.06859317
4543.2
2.28518467

12.51647
156.66207
55.00000
15.00000

Tests for Location: Mu0=0


Test
-Statistic-----p Value-----Student's t
t 32.64506
Pr > |t|
<.0001
Sign
M
15
Pr >= |M|
<.0001
Signed Rank
S
232.5
Pr >= |S|
<.0001
Test
Shapiro-Wilk
Kolmogorov-Smirnov
Cramer-von Mises
Anderson-Darling

Tests for Normality


--Statistic--W
0.981513
D
0.115808
W-Sq 0.034901
A-Sq
0.23139

-----p Value-----Pr < W


0.8642
Pr > D
>0.1500
Pr > W-Sq >0.2500
Pr > A-Sq >0.2500

J 75 1
J 56 2
J 65 3

10-14

10

Quantiles (Definition 5)
Quantile
Estimate
100% Max
99.0
99%
99.0
95%
92.0
90%
90.0
The UNIVARIATE Procedure
Variable: Score
Quantiles (Definition 5)
Quantile
Estimate
75% Q3
84.0
50% Median
74.5
25% Q1
65.0
10%
56.0
5%
54.0
1%
44.0
0% Min
44.0
Extreme Observations
----Lowest-------Highest--Value
Obs
Value
Obs
44
6
87
21
54
24
90
5
56
20
90
13
56
1
92
9
64
28
99
23
Stem
9
9
8
8
7
7
6
6
5
5
4
4

Leaf
9
002
577
144
56888
33334
5799
44
66
4

#
1
3
3
3
5
5
4
2
2
1

4
1
----+----+----+----+
Multiply Stem.Leaf by 10**+1

Boxplot
|
|
|
+-----+
| + |
*-----*
+-----+
|
|
|
|
|

Normal Probability Plot


95.5+
+++*
|
*+*+*
|
**+++
|
**++
|
***+*
|
*****
|
***++
|
+**+
|
+*+*
|
+++*
| ++++
42.5+++
*
+----+----+----+----+----+----+----+----+----+----+
-2
-1
0
+1
+2


: (N), , .
(skewness) .
(kurtosis) .
.
: , .
.
.
.

10.3 PROC MEANS

10-15

10.3. MEANS

, UNIVARIATE
MEANS, SAS
BASE, , . UNIVARIATE
, ,
.
, ,
, MEANS.
.


PROC MEANS :
PROC MEANS statistic-keywords;

, - -, MEANS
:
, , , .

. ,
MEANS:
CLM

RANGE

SKEWNESS

STDDEV

KURTOSIS
LCLM
MAX
MEAN
MIN


()

STDERR
SUM
SUMWGT
UCLM
USS

N
NMISS

VAR
PROBIT

MEDIAN(P50)
Q1 (P25)
P1
P10
P95


1%
10%
95%

T
Q3 (P75)
P5
P90
P99

()

-

5%
90%
99%

CSS
CV


, 0,05
95%.
PROC ALPHA. , 0,10,
:
PROC MEANS ALPHA=.10 CLM;

10-16

10

VAR
, MEANS
. ,
VAR.
PROC MEANS options;
VAR variable-list;


CLASS, PROC MEANS
,
. ,
() CLASS.
BY ,
. , BY,
,
.
() , CLASS.


PROC MEANS , , ( ) ,
.
( - ),
NOPRINT.
SAS , . , ,
PROC MEANS ,
, .
. MEANS.

MEANS
PROC MEANS <option(s)> <statistic-keyword(s)>;
BY <DESCENDING> variable-1 <... <DESCENDING> variable-n> <NOTSORTED>;
CLASS variable(s) </ option(s)>;
FREQ variable;
ID variable(s);
OUTPUT <OUT=SAS-data-set> <output-statistic-specification(s)>
<id-group-specification(s)> <maximum-id-specification(s)>
<minimum-id-specification(s)> </ option(s)>;
TYPES request(s);
VAR variable(s) < / WEIGHT=weight-variable>;
WAYS list;
WEIGHT variable;

10.3 PROC MEANS

10-17


, .
.

, . ,
, ,
50 . ,
, ,
:
data booklngs;
input pages @@;
cards;
34 30 29 32 52 25 24 27 31 29 24 26 30 30 30 29 21 30 25 28 28 28 29 38 28
29 24 24 29 31 30 27 45 30 22 16 29 14 16 29 32 20 20 15 28 28 29 31 29 36
;
run;
proc means data=booklngs n mean median clm alpha=.10;
title ' ';
run;

The MEANS Procedure
Analysis Variable : pages
Lower 90%
Upper 90%
N
Mean
Median
CL for Mean
CL for Mean
-----------------------------------------------------------------50
28.0000000
29.0000000
26.4419136
29.5580864
------------------------------------------------------------------

: 28, 29, ..
(50%) 29 . ,
90%
26,44 29,56 . ,
,
26 30 . ,
.

10-18

10

10.4.
FREQ

PROC FREQ SAS BASE,


. -,

.
.
FREQ :
PROC FREQ;
TABLES variable-combinations / options;
:

AGREE
CHISQ
CL
CMN
EXACT
MEASURES
PLCORR
RELRISK
TREND

, , Q-, -
-

--
22
, -,
-b, -c , D-, , ,
,

22
- ()

FREQ.

FREQ
PROC FREQ <option(s)>;
BY <DESCENDING> variable-1 <...<DESCENDING> variable-n> <NOTSORTED>;
EXACT statistic-keyword(s) </ option(s)>;
OUTPUT statistic-keyword(s) <OUT=SAS-data-set>;
TABLES request(s) </ option(s)>;
TEST statistic-keyword(s);
WEIGHT variable;


, , ,
, .
, R
E , Y N . ,
.

10.4 FREQ

data bustimes;
input bustype
cards;
E Y R Y E Y E Y E N
E Y R N E Y E Y E Y
R Y R N E N R Y R Y
;
run;

10-19

$1. +1 ontime $1. +1 @@;


E N E Y R N E Y E Y E N R N E Y E Y R N R Y E Y R N E N R
E Y R Y R N E Y E Y E Y E Y E Y R N E Y R N E Y R Y R N E
R N E N E Y R N R N R N R N E Y R N E Y E N R N R N R Y R

proc freq data=bustimes;


tables bustype*ontime / chisq;
title;
run;
The FREQ Procedure
Table of bustype by ontime
bustype
ontime
Frequency+
Percent +
Row Pct +
Col Pct + N
+ Y
+ Total
---------------------------E
+
7 +
22 +
29
+ 14.00 + 44.00 + 58.00
+ 24.14 + 75.86 +
+ 35.00 + 73.33 +
---------------------------R
+
13 +
8 +
21
+ 26.00 + 16.00 + 42.00
+ 61.90 + 38.10 +
+ 65.00 + 26.67 +
---------------------------Total
20
30
50
40.00
60.00
100.00
The FREQ Procedure
Statistics for Table of bustype by ontime
Statistic
DF
Value
Prob
------------------------------------------------------------------------------------------------Chi-Square
1
5.2386
0.0071
Likelihood Ratio Chi-Square
1
5.3364
0.0068
Continuity Adj. Chi-Square
1
5.7505
0.0165
Mantel-Haenszel Chi-Square
1
5.0939
0.0077
Phi Coefficient
-0.3805
Contingency Coefficient
0.3556
Cramer's V
-0.3805
Fisher's Exact Test
------------------------------------------------------------Cell (1,1) Frequency (F)
7
Left-sided Pr <= F
0.0081
Right-sided Pr >= F
0.9987
Table Probability (P)
Two-sided Pr <= P

0.0067
0.0097

Sample Size = 50

- 7,24 p-value 0,0071,


.
.

10-20

10

10.5. CORR

CORR SAS BASE


.
. ,
.
() 1.0 1.0.
.
CORR:
PROC CORR;

SAS
, ()
.
VAR WITH .
VAR variable-list;
WITH variable-list;

, , VAR,
, , WITH, - .
VAR,
.
, CORR . ,
, ,
. , SPEARMAN
:
PROC CORR SPERMAN;

, HOEFFDING D-
, KENDALL - . ,
- .

CORR
PROC CORR <option(s)>;
BY <DESCENDING> variable-1<...<DESCENDING> variable-n> <NOTSORTED>;
FREQ frequency-variable;
PARTIAL variable(s);
VAR variable(s);
WEIGHT weight-variable;
WITH variable(s);

10.5 CORR

10-21


,
,
.
?
data exams;
input student $1. +1 score 2. +1 television 1. +1 training 1. +1 @@;
if student ^= '' then output;
cards;
A 56 6 2 B 78 7 4 C 84 5 5 D 73 4 0 E 90 3 4
A 44 9 0 B 76 5 1 C 87 3 3 D 92 2 7 E 75 8 3
A 85 1 6 B 67 4 2 C 90 5 5 D 84 6 5 E 74 5 2
A 64 4 1 B 73 0 5 C 78 5 2 D 69 6 1 E 56 7 1
A 87 8 4 B 73 8 3 C 99 0 6 D 54 8 0 E 81 5 4
A 78 5 2 B 69 4 1 C 64 7 1 D 73 7 3 E 65 6 2
;
run;
proc corr data=exams;
var television training;
with score;
title ' ';
title2 ' ';
title3 ' ';
run;



The CORR Procedure
1 With Variables:
score
2
Variables:
television training
Variable
score
television
training

N
30
30
30

Simple Statistics
Mean
Std Dev
Sum
74.60000
12.51647
2238
5.10000
2.33932
153.00000
2.83333
1.94906
85.00000

Minimum
44.00000
0
0

Maximum
99.00000
9.00000
7.00000

Pearson Correlation Coefficients, N = 30


Prob > |r| under H0: Rho=0
score

television
training
-0.55092
0.79721
0.16
<.0001

.

.

, , ,
(0,80), (-0,55).
,
, ,
.

10-22

10

10.6. PROC REG



REG
.
SAS/STAT.
, REG

, , ,
SAS STAT ,
,
. SAS ETS
. ,
SAS.
REG .
PROC REG MODEL,
:
PROC REG;
MODEL dependent=independent;

MODEL (
) , () .
PLOT REG.
,
, . PLOT
SAS GRAPH, .
PLOT dependent=independent;

SAS GRAPH, LINEPRINTER PROC


:
PROC REG LINEPRINTER;
MODEL dependent=independent;
PLOT dependent*independent = symbol P. *
independent = symbol / OVERLAY;

symbol .

. P. .

REG. ,
, , , ,
.

10.6 PROC REG

10-23

REG
PROC REG < options > ;
< label: > MODEL dependents=<regressors> < / options > ;
BY variables ;
FREQ variable ;
ID variables ;
VAR variables ;
WEIGHT variable ;
ADD variables ;
DELETE variables ;
< label: > MTEST <equation, ... ,equation> < / options > ;
OUTPUT < OUT=SAS-data-set > keyword=names < ... keyword=names > ;
PAINT <condition | ALLOBS> < / options > | < STATUS | UNDO> ;
PLOT <yvariable*xvariable> <=symbol> < ...yvariable*xvariable> <=symbol> < /
options > ;
PRINT < options > < ANOVA > < MODELDATA > ;
REFIT;
RESTRICT equation, ... ,equation ;
REWEIGHT <condition | ALLOBS> < / options > | < STATUS | UNDO> ;
< label: > TEST equation,<, ...,equation> < / option > ;

REG
.
, .
, : H0 ,
H1 .
data ballhits;
input height distance @@;
cards;
50 110 49 135 48 129 53 150 48 124
50 143 51 126 45 107 53 146 50 154
47 136 52 144 47 124 50 133 50 128
50 118 48 135 47 129 45 126 48 118
45 121 53 142 46 122 47 119 51 134
49 130 46 132 51 144 50 132 50 131
;
run;
proc reg data=ballhits;
model distance=height;
plot distance*height;
title 'Results of Regression Analysis';
run;

10-24

10


The REG Procedure
Model: MODEL1
Dependent Variable: distance

Source
Model
Error
Corrected Total

DF
1
28
29

Analysis of Variance
Sum of
Mean
Squares
Square
1365.50831
1365.50831
2268.35836
81.01280
3633.86667

Root MSE
Dependent Mean
Coeff Var

Variable
Intercept
height

DF
1
1

9.00071
130.73333
6.88479

F Value
16.86

R-Square
Adj R-Sq

Parameter Estimates
Parameter
Standard
Estimate
Error
-11.00859
34.56363
2.89466
0.70506

Pr > F
0.0003

0.3758
0.3535

t Value
-0.32
4.11

Pr > |t|
0.7525
0.0003

10.6 PROC REG

10-25


.
:
DF
Mean Square
F value
Pr>F
Root MSE
Coeff Var
Adj R-sq


( )
F ,
()


R .

:
DF
t value
Pr>| t |


-
()

, ,
:
Distance = -11.00859 + 2.89466*Height
,
.
.
0,0003,
, .. R- 0,3758,
37,5%,
( ).
0,0003,
, .

10-26

10

10.7. ANOVA

ANOVA SAS STAT,
.
,
. ,
SAS STAT GLM,
ANOVA.
ANOVA CLASS MODEL:
PROC ANOVA;
CLASS variable-list;
MODEL dependent=effects;

CLASS MODEL
.
. MODEL
, .

. , MEANS,
, MODEL. ,
, MEANS ,
BON, DUNCAN, -,
- SCHEFF, TUKEY
MEANS effects / options;

ANOVA
PROC ANOVA < options > ;
CLASS variables ;
MODEL dependents=effects < / options > ;
ABSORB variables ;
BY variables ;
FREQ variable ;
MANOVA < test-options >< / detail-options > ;
MEANS effects < / options > ;
REPEATED factor-specification < / options > ;
TEST < H=effects > E=effect ;

10.7 ANOVA

10-27


, ,
, , .
.
data teams (keep=team height);
format team $7.;
input t $1. +1 height 2. +1 @@;
If t='r' then team='red';
If t='b' then team='blue';
If t='g' then team='gray';
If t='v' then team='violet';
If t='m' then team='magenta';
if t ^= '' then output;
cards;
r 55 r 48 r 53 r 47 r 51 r 43 r 45 r 46
b 46 b 56 b 48 b 47 b 54 b 52 b 49 b 51
g 55 g 45 g 47 g 56 g 49 g 53 g 48 g 53
v 53 v 53 v 58 v 56 v 50 v 55 v 59 v 57
m 53 m 55 m 48 m 45 m 47 m 56 m 55 m 46
;
run;
proc anova data=teams;
class team;
model height=team;
means team / scheffe;
title ' ';
run;

r
b
g
v
m

55
45
51
49
47

r
b
g
v
m

54
48
52
55
53

r
b
g
v
m

45
55
48
56
51

r
b
g
v
m

52
47
47
57
50


The ANOVA Procedure
Class Level Information
Class
team

Levels
5

Values
blue gray magenta red violet

Number of observations

60

Dependent Variable: height


Source
Model
Error
Corrected Total

DF
4
55
59
R-Square
0.231237

Source
team

Sum of
Squares
228.0000000
758.0000000
986.0000000

Coeff Var
7.279190
DF
4

Mean Square
57.0000000
13.7818182

Root MSE
3.712387

Anova SS
228.0000000

F Value
4.14

Pr > F
0.0053

height Mean
51.00000

Mean Square
57.0000000

F Value
4.14

Scheffe's Test for height


NOTE: This test controls the Type I experimentwise error rate.
Alpha
0.05
Error Degrees of Freedom
55
Error Mean Square
13.78182
Critical Value of F
2.53969
Minimum Significant Difference
4.8306

Pr > F
0.0053

10-28

10
Means with the same letter are not significantly different.
Scheffe Grouping
Mean
N
team
A
54.833
12
violet
A
B
A
50.500
12
magenta
B
A
B
A
50.333
12
gray
B
B
49.833
12
blue
B
B
49.500
12
red

12 , ,
, ANOVA.
. ,
MEANS .
:
TEAM 5 ,
. 60.

Source
DF
Sum of Square
Mean Square
F value
Pr>F
R-square
Coeff Var
Root MSE
Height Mean


,
,
( )
F , (
)
() F-
R-


, , ( 0,0053).
, .
. ,
.
A, B, C , , 0,05
RED VIOLET.

11 SAS

11.1 SAS ............................................................................ 11-3


11.2 ........................................................................ 11-7
11.3 INPUT ........................ 11-11
11.4 PUT ............................. 11-15
11.5 SAS .................... 11-19
11.6 .................................................... 11-36

11-2

11 SAS

11.1 SAS

11.1. SAS
SAS ,
. ,
.
SAS : , ,
, .
SAS

()

SAS /

ZIP

,
SAS . , ,
, ,
MEANS.
SAS ,
SUM

MEAN

MIN

MAX

VAR

STD

11-3

11-4

11 SAS

SAS , ,
. ,
.
SAS
SAS ,


SAS
U.S. ZIP



.


SAS
.

, , SAS
. SAS Language
Reference: Dictionary.
SAS
SAS
. SAS
SAS , , SAS .
SAS . , ,
MEAN
, Exam1, Exam2, and Exam3.
AvgScore=mean(exam1,exam2,exam3);

SAS , ,
. MEAN :
Exam1, Exam2 Exam3.
, .
,
. ,
.

11.1 SAS

SAS
, ,
SAS , ,
, .

SAS :
function-name(argument-1<,argument-n>);
arguments

mean(x,y,z)

mean(456,502,612,498)
mean(37*2,192/5,mean(22,34,56))
,
, function-name().

,
.
function-name(argument-1,argument-2,argument-n)

,
OF.

11-5

11-6

11 SAS

, .
, .
mean(x1,x2,x3)

.
mean(of x1-x3)

, .
mean(of newarray {*})


, , OF.
OF,
. , , ,
X1 X3, X1, X2, X3.
mean(x1-x3)


, SAS
, , .
, . ,
, , AvgScore
.
AvgScore=mean(exam1,exam2,exam3);

,
.
; 200.
,
,
. , SAS ,
. ,
LENGTH ,
, .

11.2

11.2.
,
Hrd.Temp. ,
.
, ,
PayRate. ,
PayRate .
SAS Hrd.Temp
City

State Zip

CARY
CARY
CHAPEL HILL

NC
NC
NC

27513 6224549
27513 6223251
27514 9974749

PayRate

Days

Hours

11
25
26

88
200
208

10
8
40

Phone

StartDate
14567
14524
14570

EndDate
14621
14565
14608

data hrd.newtemp;
set hrd.temp;
Salary=payrate*hours;
run;

, INPUT
. INPUT
. PUT
. .
, - INPUT PUT
, INPUT PUT
?
SAS
-- --.
. , PayRate
($). SAS
PayRate , .
.
--.
, INPUT PUT ,
.

11-7

11-8

11 SAS



.
,
, , SAS
. , , ,
PayRate .
PayRate Hours,
Salary.
data hrd.newtemp;
set hrd.temp;
Salary=payrate*hours;
run;

, SAS
PayRate ,
.
PayRate.
. PayRate
.
, , SAS log
, .
SAS Log
4
5
6
7

data hrd.newtemp;
set hrd.temp;
Salary=payrate*hours;
run;

NOTE: Character values have been converted


to numeric values at the places given
by: (Line):(Column).
6:11
NOTE: The data set HRD.NEWTEMP has 40 observations
and 19 variables.
NOTE: The data statement used 0.78 seconds.

11.2


-- ,

,
Rate
Rate=payrate;


Salary=payrate*hours;


if payrate>=rate;

, .
NewRate=sum(payrate,raise);

w.d, w


,
( ).
Character
Value

Numeric
Value

12.47

12.47

-8.96

-8.96

1.243E1

12.43

1,742.64

11-9

11-10

11 SAS

WHERE
WHERE
. , , , ,
WHERE .
Number , Character
, WHERE
.
data work.convtest;
Number=4;
Character='4';
run;
proc print data=work.convtest;
where character=4;
run;
proc print data=work.convtest;
where number='4';
run;


WHERE.
.
SAS log .
SAS Log
1
data work.convtest;
2
Number=4;
3
Character='4';
4
run;
NOTE: The data set Work.ConvTest has 1 observation
and 2 variables.
5
proc print data=work.convtest;
6
where character=4;
7
run;
ERROR: Where clause operator requires compatible
variables.
NOTE: The SAS System stopped processing this step
because
of errors.
8
proc print data=work.convtest;
9
where number='4';
10
run;
ERROR: Where clause operator requires compatible
variables.
NOTE: The SAS System stopped processing this step
because
of errors.

11.3 INPUT

11.3. INPUT

,
INPUT
. , ,
Hrd.Temp, .
, ,
PayRate Hours.
SAS Hrd.Temp
City

State Zip

Phone

CARY
CARY
CHAPEL HILL
RALEIGH

NC
NC
NC
NC

27513
27513
27514
27612

6224549
6223251
9974749
6970450

PayRate

Days

Hours

11
25
26
10

88
200
208
80

10
8
40
15

StartDate
14567
14524
14570
14516

EndDate
14621
14565
14608
14527

, .
, Hrd.Newtemp,
Salary.
data hrd.newtemp;
set hrd.temp;
Salary=payrate*hours;
run;

,
, ..
PayRate .
PayRate ,
INPUT.

11-11

11-12

11 SAS

INPUT:
INPUT(source,informat)

source ,
,

informat, ,
:
input(payrate,2.)

,
.

2115233
2,115,233

7.
COMMA9.

INPUT:
Test=input(saletest,comma9.);

COMMA9.
SaleTest.
Test.

11.3 INPUT


, INPUT
PayRate . ,
PayRate . .. PayRate 2,
2. .
input(payrate,2.)

, .
data hrd.newtemp;
set hrd.temp;
Salary=input(payrate,2.)*hours;
run;

, (
Salary).
SAS Hrd.Newtemp
City

State

Zip

Phone

CARY
CARY

NC
NC

27513
27513

6224549
6223251

PayRate

Days

Hours

Birthday

11
25

88
200

10
8

7054

StartDate EndDate
14567
14524

14621
14565

Salary
880
1600

5757

, SAS log,
INPUT.
SAS Log
13
14
15
16

data hrd.newtemp;
set hrd.temp;
Salary=input(payrate,2.)*hours;
run;

NOTE: The data set Hrd.Newtemp has 40 observations


and 19 variables.
NOTE: The DATA statement used 0.55 seconds.

11-13

11-14

11 SAS

INPUT PUT (
).
INPUT(source,informat)
PUT(source,format)
, INPUT informat,
PUT format. , format
informat, , INPUT informat.

11.4 PUT

11.4. PUT


.
,
.
, Site
,


, SiteCode:
SiteCode=site;

,
, :
SiteCode=site||dept;

,
, TRIM: Region=trim(site);

SAS log ,
.
SAS Log
4
5
6
7

data hrd.newtemp;
set hrd.temp;
SiteCode=site||dept;
run;

NOTE: Numeric values have been converted


to character values at the
places given by: (Line):(Column).
11:13
NOTE: The data set HRD.NEWTEMP has 40 observations
and 19 variables.
NOTE: The data statement used 1.06 seconds.

, INPUT,
. ,
,
, SAS .
PUT .

11-15

11-16

11 SAS


PUT ,
.
, ,
Hrd.Temp. ,
Assignment,
Site Dept.
Site, (/) ,
, Dept , 26/DP.
SAS Hrd.Temp
OverTime Job
4
.
.
.

Word processing
Filing, administrative
duties
Organizational dev.
specialist
Bookkeeping,word processing

Contract
Word Processor
Admin. Asst.
Consultant
Bookkeeper
Asst.

Dept Site
DP
PURH
PERS
BK

26
57
34
57

, (||),
, Site Dept,
. , .
.
data hrd.newtemp;
set hrd.temp;
Assignment=site||'/'||dept;
run;

, , SAS
Site ,
.. Site . Site
, .
Site ,
PUT .

11.4 PUT

PUT:
PUT(source,format)

source , ,

format, ,
, :
put(site,2.)

PUT .
PUT source, format.
Format source.
PUT ,
,
, .

.. ,
.

, PUT,

Site .
PUT,
Site . .. Site 2, 2.
. PUT ,
,
Assignment.
data hrd.newtemp;
set hrd.temp;
Assignment=put(site,2.)||'/'||dept;
run;

11-17

11-18

11 SAS

SAS Hrd.Newtemp
Overtime Job

Contact

Word processing
4
Filing, administrative
.
duties
Dept Site Birthday
DP
PURH

26
57

Word
Processor
Admin. Asst.

Assignment

7054 26/DP
5757 57/PURH

, SAS log ,
PUT.
SAS Log
13
14
15
16

data hrd.newtemp;
set hrd.temp;
Assignment=put(site,2.)||'/'||dept;
run;

NOTE: The data set Hrd.Newtemp has 40 observations


and 19 variables.
NOTE: The DATA statement used 0.71 seconds.


, , PUT,
.
PUT(source,format)
, ,
, .
PUT INPUT.
PUT(source,format)
INPUT(source,informat)
, PUT format,
INPUT informat. ,
format informat, , INPUT informat.

11.5 SAS

11-19

11.5. SAS
, SAS
SAS ,
,
SAS. SAS 1 1960 .
. :

SAS ,
. :

, SAS
, 1 1960 .
. :

SAS ,
.
SAS ,
.
data test(keep=name totday);
set hrd.temp;
TotDay=enddate-startdate;
run;

11-20

11 SAS

SAS Hrd.Temp
City State Zip
Phone
StartDate EndDate PayRate Days Hours
CARY
NC 27513 6224549
14567
14621 10
11
88
CARY
NC 27513 6223251
14524
14565 8
25
200

SAS ,
SAS .
, . , FORMAT
DATE9. StartDate EndDate. ,
, ,
PROC PRINT.
proc print data=hrd.temp;
format startdate enddate date9.;
run;

City

State Zip

CARY

NC

27513 6224549 19NOV1999 12JAN2000

10

11

88

CARY

NC

27513 6223251 07OCT1999 17NOV1999

25

200

CHAPEL HILL NC

27514 9974749 22NOV1999 30DEC1999

40

26

208

RALEIGH

27612 6970450 29SEP1999 10OCT1999

15

10

80

NC

Phone

StartDate

EndDate Pay Days Hours


Rate

SAS ,
1582 .. 20,000 ..

, .

1582 ,
1752 .

11.5 SAS

11-21

SAS
SAS , - .
.

MDY

date=mdy(mon,day,yr);

SAS

TODAY
DATE

now=today();
now=date();


SAS

TIME

curtime=time();

SAS

, , ,
SAS .

DAY

day=day(date);

(1-31)

QTR

quarter=qtr(date);

(1-4)

WEEKDAY

wkday=weekday(date);

(1-7)

MONTH

month=month(date);

(1-12)

YEAR

yr=year(date);

(4 digits)

INTCK

x=intck('day',d1,d2);
x=intck('week',d1,d2);
x=intck('month',d1,d2);
x=intck('qtr',d1,d2);
x=intck('year',d1,d2);

D1 D2
D1 D2
D1 D2
D1 D2
D1 D2

INTNX

x=intnx('interval',startfrom,increment);

,
-

SAS ,
.

11-22

11 SAS

YEAR, MONTH DAY


SAS
, . , YEAR,
MONTH DAY. ,
.

YEAR, MONTH DAY:


YEAR(date)
MONTH(date)
DAY(date)
date SAS , ,
SAS .
SAS , SAS Language Reference: Dictionary.

YEAR , ,
, 2002. MONTH ,
1 12, . 1
, 2 .. DAY
1 31, .
.

YEAR


YEAR(date)
SAS .

MONTH


SAS .

MONTH(date) 12

DAY


SAS .

DAY(date)

2002

11.5 SAS

, YEAR MONTH .
,
Hrd.Temp, ,
1999 . Hrd.Temp ,
.
SAS Hrd.Temp
City

State Zip

Phone

CARY
CARY
CHAPEL HILL
RALEIGH

NC
NC
NC
NC

6224549
6223251
9974749
6970450

27513
27513
27514
27612

StartDate
14567
14524
14570
14516

EndDate
14621
14565
14608
14527

PayRate Days Hours


10
11
88
8
25
200
40
26
208
15
10
80

, ,
YEAR ,
, StartDate. YEAR
year(startdate)

, , ,
MONTH StartDate.
month(startdate)

11-23

11-24

11 SAS

,
IF . IF
, , YEAR
1999, MONTH 11 (
).
data hrd.nov99;
set hrd.temp;
if year(startdate)=1999 and month(startdate)=11;
run;

, PROC PRINT , ,
. , PROC PRINT
FORMAT StartDate
EndDate DATE9.
data hrd.nov99;
set hrd.temp;
if year(startdate)=1999 and month(startdate)=11;
proc print data=hrd.tempnov;
format startdate enddate date9.;
run;

PROC PRINT, .
,
, 1999 .
City

State Zip

Phone

StartDate

EndDate PayRate Days Hours

CARY

NC

27513 6224549 19NOV1999 12JAN2000

10

11

88

CHAPEL HILL NC

27514 9974749 22NOV1999 30DEC1999

40

26

208

DURHAM

NC

27713 3633618 02NOV1999 13NOV1999

12

72

CARRBORO

NC

27510 9976732 16NOV1999 04JAN2000

15

64

11.5 SAS

WEEKDAY
WEEKDAY
SAS.

WEEKDAY:
WEEKDAY(date)
date SAS , ,
SAS .
SAS SAS Language Reference: Dictionary.

WEEKDAY 1 7.
.
1 =
2 =
3 =
4 =
5 =
6 =
7 =

, Radio.Sch .
AirDate SAS .
, ,
WEEKDAY IF. ,
AirDate .
data radio.schwkend;
set radio.sch;
if weekday(airdate)=7 or weekday(airdate)=1;
run;

11-25

11-26

11 SAS

MDY
MDY SAS ,
, . ,
Hrd.Temp
: Month, Day Year.
SAS Hrd.Temp
City

State Zip

Phone

CARY
CARY
CHAPEL HILL
RALEIGH

NC
NC
NC
NC

6224549
6223251
9974749
6970450

27513
27513
27514
27612

Month Day Year


1
11
12
10

12
17
30
10

2000
1999
1999
1999

PayRate Days Hours


10
8
40
15

11
25
26
10

88
200
208
80


, .
SAS ,
MDY.

MDY:
MDY(month,day,year)

month , ,
1- 12
day , , 1-31
year , , -
.

11.5 SAS

Hrd.Temp ,
Month, Day Year. MDY
SAS :
mdy(month,day,year)

,
, SAS .
data hrd.newtemp(drop=month day year);
set hrd.temp;
Date=mdy(month,day,year);
run;

, Date.
SAS Hrd.Newtemp
City

State Zip

Phone

PayRate Days Hours Date

CARY
CARY
CHAPEL HILL
RALEIGH

NC
NC
NC
NC

6224549
6223251
9974749
6970450

10
8
40
15

27513
27513
27514
27612

11
25
26
10

88
200
208
80

14621
14565
14608
14527

, SAS ,
SAS . ,
FORMAT DATE9. Date.
, PROC PRINT.
proc print data=hrd.newtemp;
format date date9.;
run;

City

State Zip Phone PayRate Days Hours

CARY

NC

27513 6224549

10

11

88 12JAN2000

CARY

NC

27513 6223251

25

200 17NOV1999

CHAPEL HILL NC

27514 9974749

40

26

208 30DEC1999

RALEIGH

27612 6970450

15

10

80 10OCT1999

NC

Date

11-27

11-28

11 SAS

MDY SAS .
,
.
, MDY.
data hrd.newtemp;
set hrd.temp;
DateCons=mdy(6,17,2002);
proc print data=hrd.newtemp;
format datecons date9.;
run;

City

State Zip Phone PayRate Days Hours DateCons

CARY

NC

27513 6224549

10

11

88 17JUN2002

CARY

NC

27513 6223251

25

200 17JUN2002

CHAPEL HILL NC

27514 9974749

40

26

208 17JUN2002

RALEIGH

27612 6970450

15

10

80 17JUN2002

NC

, .
MDY , ,
SAS
100- ,
YEARCUTOFF=. YEARCUTOFF=
1920.
Reading Date and Time Values.
, ,
MDY:

MDY(5,10,20)
= May 10, 1920
MDY(5,10,2020) = May 10, 2020

, ,
SAS DATE9.
,
Date DateCons Hrd.Newtemp.
, MDY. Dec.Review
Day. ,
.
1998 .

11.5 SAS

SAS Dec.Review
Site

Day

Westin
Stockton
Center City

12
4
17

Rate

Name

A2
A5
B1

Mitchell, K
Worton, M
Smith, A

MDY
ReviewDate. SAS
.
data dec.review98;
set dec.review;
ReviewDate=mdy(12,day,1998);
run;

SAS Dec.Review98
Site
Westin
Stockton
Center City

Day
12
4
17

Rate

Name

A2
A5
B1

Mitchell, K
Worton, M
Smith, A

ReviewDate
14225
14217
14230

MDY , SAS
.
data dec.review98;
set dec.review;
ReviewDate=mdy(15,day,1998);
run;

SAS Dec.Review98
Site
Westin
Stockton
Center City

Day
12
4
17

Rate

Name

A2
A5
B1

Mitchell, K
Worton, M
Smith, A

ReviewDate
.
.
.

11-29

11-30

11 SAS

DATE TODAY
DATE TODAY SAS .
DATE TODAY
.

DATE TODAY:
DATE()
TODAY()
,
.

, ,
Hrd.Temp. ,
:
EditDate=date();

,
, EditDate.
data hrd.newtemp;
set hrd.temp;
EditDate=date();
run;

: SAS
15 2000 .

SAS Hrd.Newtemp
EndDate EditDate
14621
14565
14608

14624
14624
14624

11.5 SAS

, SAS ,
SAS . , FORMAT
DATE9. EditDate.
, PROC PRINT.
proc print data=hrd.newtemp;
format editdate date9.;
run;

EndDate EditDate
14621 15JAN2000
14565 15JAN2000
14608 15JAN2000

DATE TODAY SAS


.
ThisDate=date();

or

ThisDate=today();

11-31

11-32

11 SAS

INTCK
INTCK .
, , ..

INTCK:
INTCK('interval',from,to)

'interval'
from SAS , -,

to SAS , -,
.
(, -)
from.

,
, interval, :
DAY
WEEKDAY
WEEK
TENDAY
SEMIMONTH
MONTH
QTR
SEMIYEAR
YEAR
, Years
2.
Years=intck('year','15jun1999'd,'15jun2001'd);

, 24
Months.
Months=intck('month','15jun1999'd,'15jun2001'd);

, 0 Years,
364 .
Years=intck('year','01jan2002'd,'31dec2002'd);

11.5 SAS

INTCK .
. , WEEK
, , from.
MONTH , YEAR
01 .
. ,
Weeks, Months Years .
SAS

0
1
1

Weeks=intck('week','31dec2000'd,'01jan2001'd);
Months=intck('month','31dec2000'd,'01jan2001'd);
Years=intck('year','31dec2000'd,'01jan2001'd);

31 2000 . , WEEK
1 2001 .. , MONTH YEAR
.
INTCK
, .
, 20-
. INTCK
Hired .
data work.anniv20;
set flights.mechanics(keep=id lastname firstname hired);
Years=intck('year',hired,today());
if years=20 and month(hired)=month(today());
proc print data=work.anniv20;
title '20-Year Anniversaries This Month';
run;

1999 .

20-Year Anniversaries This Month


Obs ID LastName FirstName
1 1403 BOWDEN

EARL

Hired Years
24DEC79

20

2 1121 HERNANDEZ MICHAEL

10DEC79

20

3 1412 MURPHEY

08DEC79

20

JOHN

11-33

11-34

11 SAS

INTNX
INTNX INTCK. INTNX
, -
.
INTNX , , ,
..

INTNX:
INTNX('interval',start-from,increment<,'alignment'>)

'interval'
start-from SAS ,
increment ,

'alignment' () ,
.
(, -)
start-from increment.

,
, interval,
:
DAY
WEEKDAY
WEEK
TENDAY
SEMIMONTH
MONTH
QTR
SEMIYEAR
YEAR
, TargetYear
SAS 13515, 1 1997 .
TargetYear=intnx('year','05feb94'd,3);

, 1
2001 . TargetMonth.
TargetMonth=intnx('semiyear','01jan2001'd,1);

11.5 SAS

INTNX
, SAS ,
1 1960 . , INTNX
, , .. ,
?
alignment:
, .
INTNX,
:
BEGINNING B
MIDDLE M
END E

.
INTNX, alignment.

SAS
MonthX=intnx('month','01jan95'd,5,'b');
MonthX=intnx('month','01jan95'd,5,'m');
MonthX=intnx('month','01jan95'd,5,'e');


12935 (June 1, 1995)
12949 (June 15, 1995)
12964 (June 30, 1995)

INTNX ,
, alignment ,
. alignment ,
.

11-35

11-36

11 SAS

11.6.
, SAS
. ,

,
Hrd.Temp.


SAS
Name

LastName

CICHOCK, ELIZABETH MARIE


BENINCASA, HANNAH LEE

FirstName

CICHOCK
BENINCASA

ELIZABETH
HANNAH

MiddleName
MARIE
LEE


SAS

Phone

Phone

6224549
6223251

4334549
4333251

.
SAS
Job
filing, administrative duties
bookkeeping, word processing, accounting

11.6


, ,
. .

SCAN

SUBSTR

TRIM

INDEX

UPCASE

LOWCASE

SCAN
SCAN
. ,
, SCAN.
Hrd.Temp
Name. Name , , .

SAS Hrd.Temp
Agency

ID

Administrative Support, Inc. F274


Administrative Support, Inc. F101
OD Consulting, Inc.
F054
Name
CICHOCK, ELIZABETH MARIE
BENINCASA, HANNAH LEE
SHERE, BRIAN THOMAS

11-37

11-38

11 SAS

, Name
: ,
.
SCAN .
SAS Hrd.Temp
Agency

ID

Administrative Support, Inc. F274


Administrative Support, Inc. F101
OD Consulting, Inc.
F054
LastName

FirstName MiddleName

CICHOCK
ELIZABETH MARIE
BENINCASA HANNAH
LEE
SHERE
BRIAN
THOMAS


SCAN ,
. ,
, , ,
SCAN .

, , . ,
, SCAN
HIGH.
. , ,
, .
209 RADCLIFFE ROAD, CENTER CITY, NY, 92716

, SCAN - NY.

11.6


SCAN,
.
, SAS
. , , ,
SCAN :

SCAN ,
, . , ,
.


SCAN,

. < ( + | & ! $ * ) ; ^ - / , %

SCAN
, , SCAN,
.

11-39

11-40

11 SAS

SCAN:
SCAN(argument,n,delimiters)

argument

n ,
delimiters ,
(' ').

SCAN
Hrd.Temp.
Name , , .
, ,
, , , .
SAS Hrd.Temp
Agency
Administrative
Administrative
OD Consulting,
New Time Temps

ID
Support, Inc. F274
Support, Inc. F101
Inc.
F054
Agency
F077

Name
CICHOCK, ELIZABETH MARIE
BENINCASA, HANNAH LEE
SHERE, BRIAN THOMAS
HODNOFF, RICHARD LEE

11.6

LastName, ,
, SCAN:
LastName=scan(name,1,' ,');

, . ,
, , ..
, .
LastName=scan(name,1);

, LastName, FirstName MiddleName,


. , Name
.
data hrd.newtemp(drop=name);
set hrd.temp;
LastName=scan(name,1);
FirstName=scan(name,2);
MiddleName=scan(name,3);
run;


SCAN 200 .
(, ,
.) , ,
, LastName, FirstName MiddleName
200. ,
.
, LENGTH
. ..
SAS ,
, ,
LENGTH , SCAN.
data hrd.newtemp(drop=name);
set hrd.temp;
length LastName FirstName MiddleName $ 10;
lastname=scan(name,1);
firstname=scan(name,2);
middlename=scan(name,3);
run;

11-41

11-42

11 SAS

SCAN SUBSTR
SUBSTR SCAN. , .
SCAN SUBSTR
:

SCAN .

SUBSTR ,
.

SUBSTR ,
, .
. ,
ID .
ID.
SAS
Name

ID

Trentonson, Matthew Robert SO45467


SR32881
Truell, Marcia Elizabeth

SUBSTR
ID. SCAN ,

11.6

SUBSTR
SUBSTR

.
Hrd.Newtemp,
: LastName, FirstName MiddleName.
SAS Hrd.Newtemp
Agency
Administrative
Administrative
OD Consulting,
New Time Temps

Support, Inc.
Support, Inc.
Inc.
Agency

ID

LastName

FirstName

MiddleName

F274
F101
F054
F077

CICHOCK
BENINCASA
SHERE
HODNOFF

ELIZABETH
HANNAH
BRIAN
RICHARD

MARIE
LEE
THOMAS
LEE

,
. ,

MiddleInitial.
SAS Work.Newtemp
Agency
Administrative
Administrative
OD Consulting,
New Time Temps

Support, Inc.
Support, Inc.
Inc.
Agency

ID

LastName

FirstName

MiddleInitial

F274
F101
F054
F077

CICHOCK
BENINCASA
SHERE
HODNOFF

ELIZABETH
HANNAH
BRIAN
RICHARD

M
L
T
L

SUBSTR
, .

11-43

11-44

11 SAS

SUBSTR:
SUBSTR(argument,position,n)

argument
.

position .

n . n ,
.

SUBSTR,
MiddleName MiddleInitial.
SAS Hrd.Newtemp
Agency
Administrative
Administrative
OD Consulting,
New Time Temps

Support, Inc.
Support, Inc.
Inc.
Agency

ID

LastName

FirstName

MiddleName

F274
F101
F054
F077

CICHOCK
BENINCASA
SHERE
HODNOFF

ELIZABETH
HANNAH
BRIAN
RICHARD

MARIE
LEE
THOMAS
LEE

SUBSTR :
substr(middlename,1,1)

,
MiddleName. 1
. , .
data work.newtemp(drop=middlename);
set hrd.newtemp;
MiddleInitial=substr(middlename,1,1);
run;

MiddleInitial , MiddleName.
MiddleName .

11.6

SAS Work.Newtemp
Agency
Administrative
Administrative
OD Consulting,
New Time Temps

Support, Inc.
Support, Inc.
Inc.
Agency

ID

LastName

FirstName

MiddleInitial

F274
F101
F054
F077

CICHOCK
BENINCASA
SHERE
HODNOFF

ELIZABETH
HANNAH
BRIAN
RICHARD

M
L
T
L

SUBSTR
, .

SUBSTR. ,
.
, 622 433.
Phone Hrd.Temp,
.
SAS Hrd.Temp
City

State Zip

Phone

CARY
CARY
CHAPEL HILL
RALEIGH

NC
NC
NC
NC

6224549
6223251
9974749
6970450

27513
27513
27514
27612

PayRate Days Hours


10
8
40
15

11
25
26
10

88
200
208
80

StartDate EndDate
14567
14524
14570
14516

14621
14565
14608
14527

11-45

11-46

11 SAS

SUBSTR
. SUBSTR,
, .
SUBSTR(argument,position,n)
, ,

. n
, .

SUBSTR
SAS SUBSTR
, .
,
.
MiddleInitial=substr(middlename,1,1);

, SUBSTR ,
.
substr(region,1,3)='NNW';

SUBSTR ,
,
. ,
Test 92,
:
substr(test,4,2)='92';
Test
Test
S7381K2
S7381K7

S7392K2
S7392K7

11.6

, , SUBSTR
622 Phone:
data hrd.temp2;
set hrd.temp;
substr(phone,1,3)='433';
run;

, 433
Phone, 1 , .
SAS Hrd.Temp
City

State Zip

CARY
NC
CARY
NC
CHAPEL HILL NC

Phone

27513 6224549
27513 6223251
27514 9974749

StartDate EndDate
14567
14524
14570

14621
14565
14608

PayRate Days Hours


10
8
40

11
25
26

88
200
208

433 Phone.
Phone, 622.
,
Phone. , SUBSTR
.
data hrd.temp2(drop=exchange);
set hrd.temp;
Exchange=substr(phone,1,3);
substr(phone,1,3)='433';
run;

IF-THEN
Exchange. - 622,
Phone.
data hrd.temp2(drop=exchange);
set hrd.temp;
Exchange=substr(phone,1,3);
if exchange='622' then substr(phone,1,3)='433';
run;

, Phone
.

11-47

11-48

11 SAS

SAS Hrd.Temp2
City

State Zip

CARY
NC
CARY
NC
CHAPEL HILL NC

Phone

StartDate EndDate

27513 4334549
27513 4333251
27514 9974749

14567
14524
14570

14621
14565
14608

PayRate Days Hours


10
8
40

11
25
26

88
200
208

SUBSTR.
SUBSTR ,
.
MiddleInitial=substr(middlename,1,1);

SUBSTR
, .
substr(region,1,3)='NNW';

TRIM
TRIM .
TRIM, , Hrd.Temp.
Hrd.Temp : Address,
City, State Zip.
SAS Hrd.Temp
Agency

ID

Name

Address

Administrative Support, Inc. F274 CICHOCK, ELIZABETH MARIE 65 ELM DR


Administrative Support, Inc. F101 BENINCASA, HANNAH LEE
11 SUN DR
City State Zip
CARY NC
CARY NC

Phone

27513 6224549
27513 6223251

StartDate EndDate PayRate Days Hours


14567
14524

14621 10
14565 8

11
25

88
200

11.6

,
Address, City Zip. (..
, State
.)
SAS Hrd.NewTemp
Agency

ID

Administrative Support, Inc.


Administrative Support, Inc.

F274 CICHOCK, ELIZABETH MARIE


F101 BENINCASA, HANNAH LEE

NewAddress

Phone

65 ELM DR, CARY, 27513 6224549


11 SUN DR, CARY, 27513 6223251

Name

StartDate EndDate PayRate Days Hours


14567
14524

14621 10
14565 8

11
25

88
200

.
,
(||), .
data hrd.newtemp(drop=address city state zip);
set hrd.temp;
NewAddress=address||', '||city||', '||zip;
run;

(||) .
, Address, City Zip
,
. , ,
, . NewAddress
, .
,
.
, , NewAddress
, .
.

11-49

11-50

11 SAS

SAS Hrd.NewTemp
NewAddress
65 ELM DRIVE
11 SUN DRIVE
712 HARDWICK STREET
5372 WHITEBUD ROAD

,
,
,
,

CARY
CARY
CHAPEL HILL
RALEIGH

,
,
,
,

27513
27513
27514
27612

NewAddress - ,
.
,
, SAS .

Address
Length=32

City
Length=15

Zip
Length=5

|65 ELM DRIVE--------------------| |RALEIGH--------| |27612|


|11 SUN DRIVE--------------------| |DURHAM---------| |27713|
|712 HARDWICK STREET-------------| |CHAPEL HILL----| |27514|

,
NewAddress,
. Zip
.

NewAddress
Length=60
|65 ELM DRIVE--------------------,RALEIGH--------,27612|
|11 SUN DRIVE--------------------,DURHAM---------,27713|
|712 HARDWICK STREET-------------,CHAPEL HILL----,27514|

11.6

TRIM
.

TRIM:
TRIM(argument)
argument ,

: trim(address)
: trim(left(id)).

NewAddress,
TRIM . Address
City.
data hrd.newtemp(drop=address city state zip);
set hrd.temp;
NewAddress=trim(address)||', '||trim(city)||', '||zip;
run;
NewAddress,

.
SAS Hrd.Newtemp
NewAddress
65 ELM DRIVE, CARY, 27513
11 SUN DRIVE, CARY, 27513
712 HARDWICK STREET, CHAPEL HILL, 27514
5372 WHITEBUD ROAD, RALEIGH, 27612

11-51

11-52

11 SAS

, TRIM , .
, , ,
.
,
, .
. , ,
Address Street.
Street,
, 20.
data temp;
set hrd.temp;
length Street $ 20;
Street=trim(address);
run;
Address
Length=32

Street
Length=20

|65 ELM DRIVE--------------------| |65 ELM DRIVE--------|


|11 SUN DRIVE--------------------| |11 SUN DRIVE--------|
|712 HARTWICK STREET-------------| |712 HARTWICK STREET-|

INDEX
INDEX
. INDEX ,
.
, 0.
, Job,
. ,
,
.
SAS Hrd.Temp
Job

Contact

Dept

word processing
WORD PROCESSOR DP
filing, administrative duties ADMIN. ASST.
PURH
organizational dev. specialist CONSULTANT
PERS

Site
26
57
34

11.6

INDEX .

INDEX:
INDEX(source,excerpt)

source

excerpt ,
(' ').

Job,
INDEX, . , ,
.
index(job,'word processing')

, , INDEX
IF. ,
, 0, .
data hrd.datapool;
set hrd.temp;
if index(job,'word processing') > 0;
run;

, ,
.
SAS Hrd.Datapool
Job

Contact

Dept

Site

word processing
bookkeeping, word processing
word processing, sec. work
bookkeeping, word processing
word processing
word processing, sec. work
word processing
word processing

WORD PROCESSOR
BOOKKEEPER AST
WORD PROCESSOR
BOOKKEEPER AST
WORD PROCESSOR
WORD PROCESSOR
WORD PROCESSOR
WORD PROCESSOR

DP
BK
DP
BK
DP
PUB
DP
DP

26
57
95
44
59
38
44
90

11-53

11-54

11 SAS

, INDEX ,
, , ,
, . , INDEX,
, ,
.
index(job,'WORD PROCESSING')

SAS Hrd.Temp
Job

Contact

Dept

Site

word processing
filing, administrative duties
organizational dev. specialist
bookkeeping, word processing

WORD PROCESSOR
ADMIN. ASST.
CONSULTANT
BOOKKEEPER ASST.

DP
PURH
PERS
BK

26
57
34
57


UPCASE LOWCASE
INDEX , ,
. UPCASE LOWCASE
.
, INDEX.
index(upcase(job),'WORD PROCESSING')
index(lowcase(job),'word processing')

UPCASE
UPCASE .

UPCASE:
UPCASE(argument)
argument SAS , ,
.

11.6

, UPCASE
Hrd.Temp. Job
.
SAS Hrd.Temp
Job
word processing
filing, administrative duties
organizational dev. specialist
bookkeeping, word processing

Contact
WORD PROCESSOR
ADMIN. ASST.
CONSULTANT
BOOKKEEPER ASST.

Dept
DP
PURH
PERS
BK

Site
26
57
34
57

Job , UPCASE
:
upcase(job)

, .
Job .
data hrd.newtemp;
set hrd.temp;
Job=upcase(job);
run;

,
Job.
SAS Hrd.Newtemp
Job

Contact

Dept Site

WORD PROCESSING
FILING, ADMINISTRATIVE DUTIES
ORGANIZATIONAL DEV. SPECIALIST
BOOKKEEPING, WORD PROCESSING

WORD PROCESSOR
ADMIN. ASST.
CONSULTANT
BOOKKEEPER ASST.

DP
PURH
PERS
BK

26
57
34
57

11-55

11-56

11 SAS

LOWCASE
LOWCASE .

LOWCASE:
LOWCASE(argument)
argument SAS , ,
.

LOWCASE.
Title .
lowcase(title)

LOWCASE .
LOWCASE
Contact .
SAS Hrd.Temp
Job

Contact

Dept Site

word processing
WORD PROCESSOR DP
26
filing, administrative duties ADMIN. ASST.
PURH 57
organizational dev. specialist CONSULTANT
PERS 34

data hrd.newtemp;
set hrd.temp;
Contact=lowcase(contact);
run;

, .
Contact.
SAS Hrd.Newtemp
Job

Contact

Dept Site

word processing
word processor DP
26
filing, administrative duties admin. asst.
PURH 57
organizational dev. specialist consultant
PERS 34

11.6

TRANWRD
TRANWRD .

TRANWRD:
TRANWRD(source,target,replacement)

source ,
target , SAS source
replacement , target.
target replacement
. ,
(' ' " ").

TRANWRD
. , Name,
Monroe Manson.
name=tranwrd(name,'Monroe','Manson')

TRANWRD . ,
TRANWRD
Miss Mrs. Ms..
SAS Work.Before
Name
Mrs.
Miss
Mrs.
Miss

Millicent Garrett Fawcett


Charlotte Despard
Emmeline Pankhurst
Sylvia Pankhurst

11-57

11-58

11 SAS

data work.after;
set work.before;
name=tranwrd(name,'Miss','Ms.');
name=tranwrd(name,'Mrs.','Ms.');
run;

, .
Name.
SAS Work.After
Name
Ms.
Ms.
Ms.
Ms.

Millicent Garrett Fawcett


Charlotte Despard
Emmeline Pankhurst
Sylvia Pankhurst


, SAS


SAS
.

SAS
. :
, .
, ,
.

11.6

INT
INT . INT
.

INT:
INT(argument)
argument ,
.

, ,
INT.

SAS
Work.After

SAS
Work.Before
Examples
326.54
98.20
-32.66
1401.75

data work.after;
set work.before;
Examples=int(examples);
run;

Examples
326
98
-32
1401

11-59

11-60

11 SAS

ROUND
ROUND .

ROUND:
ROUND(argument,round-off-unit)

argument ,
.
round-off-unit .

, , ,
- 1, . ,
, ,
ROUND.

SAS
Work.After

SAS
Work.Before
Examples
326.54
98.20
-32.66
1401.75

data work.after;
set work.before;
Examples=round(examples,.2);
run;

Examples
326.60
98.20
-32.60
1401.80

SAS,
, SAS Language Reference: Concepts
SAS Language Reference: Dictionary.