목차
Lecture 06
자료다루기
자료간의 연결관계 (Data Relationship)
자료의 결합(combining multiple data sets )
결합방법 (6가지 method)
세로결합
1. 상하 자료결합(Concatenating) (SET, PROC APPEND, SQL)
2. 세로 끼워 넣기 (interleaving)
3. SET 문에 의한 가로 결합 (One-to-one reading)
4. MERGE 문에 의한 자료결합 ---> 가로 결합에 변수를 추가하는 경우
4.2 Match Merging (MERGE 문에 의한 대응가로결합)
자료다루기
자료간의 연결관계 (Data Relationship)
자료의 결합(combining multiple data sets )
결합방법 (6가지 method)
세로결합
1. 상하 자료결합(Concatenating) (SET, PROC APPEND, SQL)
2. 세로 끼워 넣기 (interleaving)
3. SET 문에 의한 가로 결합 (One-to-one reading)
4. MERGE 문에 의한 자료결합 ---> 가로 결합에 변수를 추가하는 경우
4.2 Match Merging (MERGE 문에 의한 대응가로결합)
본문내용
0 0 2 0 0 0 1.000
양준혁 2003.04.24 기아 4 4 0 0 0 0 0 0 0 0 0 0 2 1 0.000
양준혁 2003.04.22 기아 3 3 0 0 0 0 0 0 0 0 0 0 0 0 0.000
진갑용 2003.04.26 LG 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0.000
진갑용 2003.04.26 LG 4 4 0 0 0 0 0 0 0 0 0 0 0 1 0.000
진갑용 2003.04.24 기아 4 2 0 1 0 0 0 0 0 0 2 0 0 0 0.500
진갑용 2003.04.22 기아 3 2 0 2 1 0 0 0 0 0 0 1 0 0 1.000
진갑용 2003.04.19 SK 4 4 1 1 0 0 0 1 1 0 0 0 2 0 0.250
강명구 2003.04.24 기아 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.000
강명구 2003.04.17 현대 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0.000
강명구 2003.04.15 현대 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.000
강명구 2003.04.11 한화 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0.000
예) 자료결합 종합예제
* c:\sas\myprog\datamanip.sas;
/* Basic Data set manipulation;
SET DELETE DROP PRINT IN= LIST OPTIONS
MERGE BY FIRST. LAST. UPDATE KEEP= TITLE
1. Read permament SAS data set
2. Taking a subset of the observations
3. Taking a subset of the variables
4. Adding new variables
5. Combining several operations
6. Multiple output data sets
7. Concatenation
8. Interleaving
9. Merging
10. Updating */
dm 'log; clear; output; clear';
OPTIONS LS=72 nocenter nodate nonumber;
TITLE;
libname c 'c:\sas\myprog';
DATA body;
set c.body(obs=20);
if gender =1 then sex= 'M'; else sex = 'F';
if height > 158;
keep id age sex height weight;
PROC PRINT; TITLE 'Original data set';
DATA b; SET body; IF sex='M' THEN DELETE;
PROC PRINT; TITLE 'Subset of observations: Female';
DATA C; SET body; DROP height weight;
PROC PRINT; TITLE 'Subset of variables: DROP weight height';
DATA d; SET body; birthyr=2000-age;
PROC PRINT; TITLE 'Adding a new wariable';
DATA e; SET body;
IF sex='M' THEN DELETE;
DROP height weight;
birthyr=2000-age;
PROC PRINT; TITLE 'Combining several operations';
DATA males females; KEEP id;
SET body;
IF sex='M' THEN OUTPUT males;
IF sex='F' THEN OUTPUT females;
PROC PRINT DATA=males; TITLE 'males - First output data set';
PROC PRINT DATA=females; TITLE 'females - second output data set';
DATA both;
SET males(IN=m) females(IN=f);
IF m THEN sex='M'; IF f THEN sex='F';
PROC PRINT; TITLE 'Concatenated data sets';
DATA both;
SET males(IN=m) females(IN=f); BY id;
IF m THEN sex='M'; IF f THEN sex='F';
PROC PRINT; TITLE 'Interleaved data set';
DATA library; INPUT id date textbook $12.; CARDS;
4 2 English
6 2 Science
6 3 English
7 1 Art
11 4 Arithematic
12 5 Sewing
15 2 Art
17 1 Mechanics
19 2 Science
PROC PRINT; TITLE 'Library transaction data set';
DATA newbody;
MERGE body(IN=C) library; BY id;
IF C & LAST.id;
PROC PRINT;
TITLE 'For each person what is the most recently checked book?';
DATA newlib;
MERGE library(IN=l) body(KEEP=id age sex); BY id;
IF l;
PROC PRINT;
TITLE 'For each library transaction, what is the the age and sex of cheker';
DATA transact;
INPUT id sex $ age height weight comment $ 24-50; LIST; CARDS;
20 . . 170 75 Update new height weight
41 F 13 160 55 Additional record
72 M 13 170 60 Additional record
PROC PRINT; TITLE 'Transactions'; RUN;
DATA body2;
UPDATE body transact(drop=comment); BY id;
PROC PRINT; TITLE 'New updated master file'; RUN;
양준혁 2003.04.24 기아 4 4 0 0 0 0 0 0 0 0 0 0 2 1 0.000
양준혁 2003.04.22 기아 3 3 0 0 0 0 0 0 0 0 0 0 0 0 0.000
진갑용 2003.04.26 LG 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0.000
진갑용 2003.04.26 LG 4 4 0 0 0 0 0 0 0 0 0 0 0 1 0.000
진갑용 2003.04.24 기아 4 2 0 1 0 0 0 0 0 0 2 0 0 0 0.500
진갑용 2003.04.22 기아 3 2 0 2 1 0 0 0 0 0 0 1 0 0 1.000
진갑용 2003.04.19 SK 4 4 1 1 0 0 0 1 1 0 0 0 2 0 0.250
강명구 2003.04.24 기아 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.000
강명구 2003.04.17 현대 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0.000
강명구 2003.04.15 현대 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.000
강명구 2003.04.11 한화 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0.000
예) 자료결합 종합예제
* c:\sas\myprog\datamanip.sas;
/* Basic Data set manipulation;
SET DELETE DROP PRINT IN= LIST OPTIONS
MERGE BY FIRST. LAST. UPDATE KEEP= TITLE
1. Read permament SAS data set
2. Taking a subset of the observations
3. Taking a subset of the variables
4. Adding new variables
5. Combining several operations
6. Multiple output data sets
7. Concatenation
8. Interleaving
9. Merging
10. Updating */
dm 'log; clear; output; clear';
OPTIONS LS=72 nocenter nodate nonumber;
TITLE;
libname c 'c:\sas\myprog';
DATA body;
set c.body(obs=20);
if gender =1 then sex= 'M'; else sex = 'F';
if height > 158;
keep id age sex height weight;
PROC PRINT; TITLE 'Original data set';
DATA b; SET body; IF sex='M' THEN DELETE;
PROC PRINT; TITLE 'Subset of observations: Female';
DATA C; SET body; DROP height weight;
PROC PRINT; TITLE 'Subset of variables: DROP weight height';
DATA d; SET body; birthyr=2000-age;
PROC PRINT; TITLE 'Adding a new wariable';
DATA e; SET body;
IF sex='M' THEN DELETE;
DROP height weight;
birthyr=2000-age;
PROC PRINT; TITLE 'Combining several operations';
DATA males females; KEEP id;
SET body;
IF sex='M' THEN OUTPUT males;
IF sex='F' THEN OUTPUT females;
PROC PRINT DATA=males; TITLE 'males - First output data set';
PROC PRINT DATA=females; TITLE 'females - second output data set';
DATA both;
SET males(IN=m) females(IN=f);
IF m THEN sex='M'; IF f THEN sex='F';
PROC PRINT; TITLE 'Concatenated data sets';
DATA both;
SET males(IN=m) females(IN=f); BY id;
IF m THEN sex='M'; IF f THEN sex='F';
PROC PRINT; TITLE 'Interleaved data set';
DATA library; INPUT id date textbook $12.; CARDS;
4 2 English
6 2 Science
6 3 English
7 1 Art
11 4 Arithematic
12 5 Sewing
15 2 Art
17 1 Mechanics
19 2 Science
PROC PRINT; TITLE 'Library transaction data set';
DATA newbody;
MERGE body(IN=C) library; BY id;
IF C & LAST.id;
PROC PRINT;
TITLE 'For each person what is the most recently checked book?';
DATA newlib;
MERGE library(IN=l) body(KEEP=id age sex); BY id;
IF l;
PROC PRINT;
TITLE 'For each library transaction, what is the the age and sex of cheker';
DATA transact;
INPUT id sex $ age height weight comment $ 24-50; LIST; CARDS;
20 . . 170 75 Update new height weight
41 F 13 160 55 Additional record
72 M 13 170 60 Additional record
PROC PRINT; TITLE 'Transactions'; RUN;
DATA body2;
UPDATE body transact(drop=comment); BY id;
PROC PRINT; TITLE 'New updated master file'; RUN;
키워드
추천자료
미공개 자료를 구함니다.(전자상거래에 관해)
[A+평가자료]썩은 사과 독후감 서평, 개인적인 감상과 느낀 점과 교훈은 무엇인가?.
[우수평가자료]오토코마에 두부 독후감 서평, 개인적인 감상과 느낀 점과 교훈은 무엇인가?.
[A+자료] 발달심리
[인간행동과사회환경a+자료] 태아기, 유아기, 학령전기에 대해서
[a+자료]가족상담및치료 - 학교폭력[청소년 폭력]에 대해서
(A+자료) 촛불시위의 의의와 특징 및 인터넷 정치와의 연관성과 적용 조사분석
테마상가 발표자료(테마상가 개념 및 상가분류)
(우수평가자료)[인적자원관리]전문성을 살리는 경력관리
[강의자료] 중소기업 제조현장의 이해와 개선 {중소기업 제조현장의 이해, 생산성 향상/도요...
(★우수자료★) S-Project (The Museum Sex & Health) - 사업계획서 성 박물관 설립 사업계...
(★우수자료★) 부동산 문제와 대안 - 한국부동산의 문제점 한국부동산의 현황, 한국부동산의 특징
교육행정 정리자료