DATA step 실행과정
Infile 할 때 SAS 내부에서 어떻게 읽어들이는지 DATA step실행과정에 대해 알아보겠습니다.
위와 같은 SAS data set이 만들어지는 과정을 예로 들어보겠습니다.
DATA step 실행과정은 크게 Compiling과정과 Executing과정으로 나누어집니다.
1. Comliling
① Input Buffer : raw data 공간 확보
data aa.student;
infile 'F:\ex\student.txt'; <-
input ID $ 1-3 Age 5-6 Sex $ 8 Weight 10-13 Height 15-19;
run;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data aa.student;
infile 'F:\ex\student.txt';
input ID $ 1-3 <- Age 5-6 Sex $ 8 Weight 10-13 Height 15-19;
run;
|
PDV
ID
$ 3
|
|
data aa.student;
infile 'F:\ex\student.txt';
input ID $ 1-3 Age 5-6 <- Sex $ 8 Weight 10-13 Height 15-19;
run;
|
PDV ( ※ 숫자변수는 무조건 8바이트로 생성)
ID $ 3 |
Age 8 |
|
|
.
.
.
PDV
ID $3 |
Age 8 |
Sex $1 |
Weight 8 |
Height 8 |
|
|
|
|
|
③ SAS data set의 description 생성 : PDV안의 정보를 output으로 내보냄
data aa.student;
infile 'F:\ex\student.txt';
input ID $ 1-3 Age 5-6 Sex $ 8 Weight 10-13 Height 15-19;
run; <-
|
Input Buffer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PDV
ID |
Age |
Sex |
Weight |
Height |
|
|
|
|
|
description portion
ID $3 |
Age 8 |
Sex $1 |
Weight 8 |
Height 8 |
2. Executing
raw data
100 18 F 49.0 158.5 101 17 M 65.8 172.5 102 17 F 54.5 167.3 103 19 F 51.3 160.9 104 18 M 78.0 181.1 105 18 M 78.6 177.7 |
data aa.student;
infile 'F:\ex\student.txt';
input <- ID $ 1-3 Age 5-6 Sex $ 8 Weight 10-13 Height 15-19;
run;
|
Input Buffer
1 |
0 |
0 |
|
1 |
8 |
|
F |
|
4 |
9 |
. |
0 |
|
1 |
5 |
8 |
. |
5 |
ID |
Age |
Sex |
Weight |
Height |
|
|
|
|
|
description portion
ID $3 |
Age 8 |
Sex $1 |
Weight 8 |
Height 8 |
②
data aa.student;
infile 'F:\ex\student.txt';
input ID $ 1-3 <- Age 5-6 Sex $ 8 Weight 10-13 Height 15-19;
run;
|
Input Buffer
1 |
0 |
0 |
|
1 |
8 |
|
F |
|
4 |
9 |
. |
0 |
|
1 |
5 |
8 |
. |
5 |
ID |
Age |
Sex |
Weight |
Height |
100 |
|
|
|
|
description portion
ID $3 |
Age 8 |
Sex $1 |
Weight 8 |
Height 8 |
data aa.student;
infile 'F:\ex\student.txt';
input ID $ 1-3 Age 5-6 <- Sex $ 8 Weight 10-13 Height 15-19;
run;
|
Input Buffer
1 |
0 |
0 |
|
1 |
8 |
|
F |
|
4 |
9 |
. |
0 |
|
1 |
5 |
8 |
. |
5 |
ID |
Age |
Sex |
Weight |
Height |
100 |
18 |
|
|
|
description portion
ID $3 |
Age 8 |
Sex $1 |
Weight 8 |
Height 8 |
data aa.student;
infile 'F:\ex\student.txt';
input ID $ 1-3 Age 5-6 Sex $ 8 <- Weight 10-13 Height 15-19;
run;
|
Input Buffer
1 |
0 |
0 |
|
1 |
8 |
|
F |
|
4 |
9 |
. |
0 |
|
1 |
5 |
8 |
. |
5 |
ID |
Age |
Sex |
Weight |
Height |
100 |
18 |
F |
|
|
description portion
ID $3 |
Age 8 |
Sex $1 |
Weight 8 |
Height 8 |
⑤
data aa.student;
infile 'F:\ex\student.txt';
input ID $ 1-3 Age 5-6 Sex $ 8 Weight 10-13 <- Height 15-19;
run;
|
Input Buffer
1 |
0 |
0 |
|
1 |
8 |
|
F |
|
4 |
9 |
. |
0 |
|
1 |
5 |
8 |
. |
5 |
ID |
Age |
Sex |
Weight |
Height |
100 |
18 |
F |
49.0 |
|
description portion
ID $3 |
Age 8 |
Sex $1 |
Weight 8 |
Height 8 |
⑥
data aa.student;
infile 'F:\ex\student.txt';
input ID $ 1-3 Age 5-6 Sex $ 8 Weight 10-13 Height 15-19 <- ;
run;
|
Input Buffer
1 |
0 |
0 |
|
1 |
8 |
|
F |
|
4 |
9 |
. |
0 |
|
1 |
5 |
8 |
. |
5 |
ID |
Age |
Sex |
Weight |
Height |
100 |
18 |
F |
49.0 |
158.5 |
description portion
ID $3 |
Age 8 |
Sex $1 |
Weight 8 |
Height 8 |
⑦ PDV안의 내용이 output으로 => Automatic output
data aa.student;
infile 'F:\ex\student.txt';
input ID $ 1-3 Age 5-6 Sex $ 8 Weight 10-13 Height 15-19;
run; <- output으로 출력, 다시 올라가서 return. (끌날 때까지)
|
Input Buffer
1 |
0 |
0 |
|
1 |
8 |
|
F |
|
4 |
9 |
. |
0 |
|
1 |
5 |
8 |
. |
5 |
ID |
Age |
Sex |
Weight |
Height |
100 |
18 |
F |
49.0 |
158.5 |
description portion
ID $3 |
Age 8 |
Sex $1 |
Weight 8 |
Height 8 |
100 |
18 |
F |
49.0 |
158.5 |
⑧
data aa.student; <-
infile 'F:\ex\student.txt';
input ID $ 1-3 Age 5-6 Sex $ 8 Weight 10-13 Height 15-19;
run;
|
Input Buffer
1 |
0 |
0 |
|
1 |
8 |
|
F |
|
4 |
9 |
. |
0 |
|
1 |
5 |
8 |
. |
5 |
PDV <- PDV 초기화
ID |
Age |
Sex |
Weight |
Height |
|
|
|
|
|
description portion
ID $3 |
Age 8 |
Sex $1 |
Weight 8 |
Height 8 |
100 |
18 |
F |
49.0 |
158.5 |
⑨
data aa.student;
infile 'F:\ex\student.txt';
input <- ID $ 1-3 Age 5-6 Sex $ 8 Weight 10-13 Height 15-19;
run;
|
Input Buffer
1 |
0 |
1 |
|
1 |
7 |
|
M |
|
6 |
5 |
. |
8 |
|
1 |
7 |
2 |
. |
5 |
PDV
ID |
Age |
Sex |
Weight |
Height |
|
|
|
|
|
description portion
ID $3 |
Age 8 |
Sex $1 |
Weight 8 |
Height 8 |
100 |
18 |
F |
49.0 |
158.5 |
⑩
data aa.student;
infile 'F:\ex\student.txt';
input ID $ 1-3 Age 5-6 Sex $ 8 Weight 10-13 Height 15-19; <-
run;
|
Input Buffer
1
|
0
|
1
|
|
1
|
7
|
|
M
|
|
6
|
5
|
.
|
8
|
|
1
|
7
|
2
|
.
|
5
|
PDV
ID
|
Age
|
Sex
|
Weight
|
Height
|
101
|
17
|
M
|
65.8
|
172.5
|
description portion
ID $3 |
Age 8 |
Sex $1 |
Weight 8 |
Height 8 |
100 |
18 |
F |
49.0 |
158.5 |
⑪
data aa.student;
infile 'F:\ex\student.txt';
input ID $ 1-3 Age 5-6 Sex $ 8 Weight 10-13 Height 15-19;
run; <-
|
Input Buffer
1
|
0
|
1
|
|
1
|
7
|
|
M
|
|
6
|
5
|
.
|
8
|
|
1
|
7
|
2
|
.
|
5
|
PDV
ID
|
Age
|
Sex
|
Weight
|
Height
|
101
|
17
|
M
|
65.8
|
172.5
|
description portion
ID $3 |
Age 8 |
Sex $1 |
Weight 8 |
Height 8 |
100 |
18 |
F |
49.0 |
158.5 |
101 |
17 |
M |
65.8 |
172.5 |
위 과정을 raw data를 모두 읽을 때까지 반복하고, 다 읽어들인 후 SAS data set이 생성됩니다.