processing sas data sets 2contents.kocw.net/kocw/document/2014/gacheon/kimnamh... · 2016-09-09 ·...
TRANSCRIPT
Processing SAS Data Sets_2
Statistical Data Analysis 1
Namhyoung Kim
Dept. of Applied Statistics
Gachon University
1
Changing Observations to Variables Using PROC TRANSPOSE
PROC TRANSPOSE PROC TRANSPOSE DATA= SAS-data-set options;
BY variables; ID variable; VAR variables;
RUN; BY statement: You can use the BY statement if you have any
grouping variables that you want to keep as variables. (X in example)
ID statement: specify a variable whose values name the transposed variables (Y in example)
VAR statement: list the variables to transpose (z in example) The TRANSPOSE procedure automatically generates the
_NAME_ variable2
Changing Observations to Variables Using PROC TRANSPOSE
Example 8.13
3
Changing Observations to Variables Using PROC TRANSPOSE
Example 8.14
4
Managing SAS Data Set Using PROC DATASETS
The DATASETS procedure is a utility procedure that manages your SAS files
APPEND statement append SAS data sets
NOLIST: Suppress the printing of the directory FORCE: forces the APPEND statement to concatenate data sets
when the DATA= data set contains variables that either are not in the BASE= data set do not have the same type as the variables in the BASE=
data set are longer than the variables in the BASE= data set.
5
Managing SAS Data Set Using PROC DATASETS
CONTENTS statement list the attributes of a SAS data set, such as:
the date when the data was last modified whether the data is compressed whether the data is indexed
6
Managing SAS Data Set Using PROC DATASETS
COPY statement copy SAS files from one SAS library to another
DELETE statement delete SAS files
CHANGE and EXCHANGE statements rename SAS files
7
Managing SAS Data Set Using PROC DATASETS
Example 8.17 8.18
8
Managing SAS Data Set Using PROC DATASETS
MODIFY statement
9
Store the SAS log or Procedure Output
PROC PRINTTO PROC PRINTTO options;
RUN;
Options PRINT=‘filename’ : route procedure output to a permanent
external file. LOG=‘filename’ : route the SAS log to a permanent external
file. NEW : replace the file instead of appending to it
10
Store the SAS log or Procedure Output
Example 8.20
11
Using ODS Statements to Create HTML Output
Output Delivery System Procedures produce only data and send that data
to the ODS which determines where the output should go(destination) and what it should look like when it gets there
Destinations LISTING: Whenever you don’t specify a destination,
your output will be sent, by default, to the listing(output window)
HTML: Hypertext Markup Language PDF: Portable Document Format OUTPUT: SAS output data set
12
Using ODS Statements to Create HTML Output
Example 8.21
13
AUTOEXEC File
The AUTOEXEC.SAS file is a regular text file that contains SAS statements that are executed when SAS is first started.
AUTOEXEC.SAS is an external file located in the same physical location as SAS.EXE.
14
AUTOEXEC File
Example 8.22
15
Practice
8-1 다음 데이터는 5명의 사람으로부터 설문문항들을 조사한 것으로, 첫 세 개의 열은 응답자의 id, 네 번째 열은 성별, 다섯 번째 열은연령대, 나머지 열들에는 세 개의 설문문항이 각각 하나의 열로 기록되어 있는 데이터이다. 각각의 변수명은 id, gender, agegrp, item1, item2, item3라고 하자. 이때 item1, item2, item3 변수들의합을 구한 다음 그 합이 큰 값에서부터 작은 값의 순으로 정렬한 결과를 저장한 새로운 데이터셋을 생성하여라.
16
Practice
8-2 문제8-1에서 만든 데이터셋에서 성별이 m인 경우만 출력해 보아라.
8-3 문제 8-1의 데이터에 대해서 다음표와 같이 재표현하는 프로그램을 작성하여라. a. 변수 gender에 대해 m=Male, f=Female. b. 변수 agegrp에 대해 1=20세 이하, 2=21세 이상 40세
이하, 3=41세 이상 60세 이하, 4=60세 이상. c. 변수 item1-item3에 대해 1=강한 부정, 2=부정, 3=그저
그러함, 4=긍정, 5=강한 긍정. <힌트> FORMAT 프로시저를 사용하여 각 변수에 대해 사
용자 출력포맷을 작성하고 데이터 단계에서 FORMAT 명령문으로 포맷을 지정할 것.
17
Practice
8-4 4개의 변수(Company, Debt, AccountNumber, Town)에 대한 자료값들이 다음과 같을 때, 이를 SAS 데이터셋으로 생성하고 마을(Town)과 회사(Company)에 따라 정렬하여라.
18
Practice
8-5 문제 8-4번에서 정렬한 데이터셋을 PRINT 프로시저를 이용하여 마을(Town)별로 부채(Debt)의 합을 출력하여라.
19
Practice
8-6 4개의 변수(Company, Date, Time, Price)에 대한 자료값들이 다음과 같을 때, 이를 SAS 데이터셋으로 생성하고, Transpose 프로시저를 이용하여 회사(Company)의 각 수준을 그룹으로 하여 개체와변수의 위치를 바꾸어라. 이때 날짜(Date)변수의 항목을 새로운 변수로 지정하여라.
20
Practice
8-7 DATASETS 프로시저를 이용하여 기존 데이터셋에 새로운 데이터셋의 개체를 추가하여라. 이때 기존 데이터셋에 존재하는 변수들에 대해서만 개체를 추가하여라.
21
기존데이터셋
새로운데이터셋
Practice
8-8 세 개의 변수(Name, Present, Taste)에 대한자료값들이 다음과 같을 때, 이를 SAS 데이터셋으로 생성하고, RANKS명령문을 이용하여 변수Present와 Taste에 대해서 순위값을 출력하여라.
22
Practice
8-9 sashelp.shoes 데이터를 이용하여 Product를Boot에 한정하여 지역(Region)별로 판매액(Sales)의 기초통계량을 출력하고 비교하여라.
23