Chapter 2 Reading Data into SAS

Chapter 2 Reading Data into SAS - STAT1303 Data Management...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
STAT1303 Data Management 2. Reading Data 2 Reading Data After the introduction of SAS, reading data into the SAS system can be considered as the Frst step in the data analysis by computer software. In this chapter, we assume that the raw data are saved in an external ASCII Fle or included in the SAS program directly. 2.1 Raw Data Input Converting non-SAS data (or raw data) into a SAS data set is a fundamental task in a Data Step. Basically, 3 styles of raw data input are available for the Data Step, namely, (1) LIST input, (2) COLUMN input and (3) ±ORMATTED input. ±or practical use, these 3 methods can be used with combination. Usually, raw data are arranged in one of the following 2 styles: Case 1. Data values come consecutively and are not aligned across lines. XXXXX YYYY ZZZZ UUUUUUUU XX YYYY ZZZZZ UU XXXXXXXX YY ZZZZZZ UUUU Case 2. Data values are aligned across lines. XXXXX YYYY ZZZZ UUUUUUUU XX YYYY ZZZZZ UU XXXXXXXX YY ZZZZZZ UUUU Alternatively, other forms of data input are available in SAS., for example, 1. Data may be entered into computer using another software, e.g. Excel, and Access and etc. . 2. SAS provides facilities to convert data from some common software packages into SAS data sets. 3. SAS can directly access the data Fle/system through SAS/ACCESS, ODBC driver and so on. HKU STAT1303 (2011-12, Semester 1) 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
STAT1303 Data Management 2. Reading Data 2.1.1 How Does Data Step Work? 2.1.1.1 Steps in Data Step Execution 1. When Data Step starts, an input bu f er and a program data vector (PDV) are created. 2. The program loops through the following until no more inpu trecordcanbe read. (a) Sets variable values to missing in the program data vector(PDV) . HKU STAT1303 (2011-12, Semester 1) 2
Background image of page 2
STAT1303 Data Management 2. Reading Data (b) Read an input record through the input bu f er and assign variable values to the program data vector (PDV). (c) Execute additional executable statements. (d) Write an observation to the SAS data set from the program data vector (PDV). 2.1.2 LIST Input For LIST input, there must be a separator between data values in the ±rst style of raw data and this separator is called a delimiter .Supp o s eth esp a c ec h a r a c t e ri s the delimiter. Then, the data will be arranged in the following style. XXXXX YYYY ZZZZ UUUUUUUU XX YYYY ZZZZZ UU XXXXXXXX YY ZZZZZZ UUUU When the data values are separated by a delimiter character (most commonly used is a blank space), the LIST input can be used. The LIST input means the input data are organized in a list form - variable 1 of observation 1 comes ±rst, then variable 2 of observation 1, and so on, then variable 1 of observation 2, and so on; with each ±eld separated by a delimiter. Example 2.1. ASASdatasetRATiscreatedbytheLISTinputo frawdata . *Example2.1-LISTinput; data rat; /* create SAS data set ’rat’ */ input litter $ weighta weightb weighti weightj; cards; A61.55552.542 B60.350.856.551.3 I3756.339.750 J5959.545.244.8 ; run; Here, the INPUT statement reads data into variables speci±ed in the statement, in the exact order of the variables appeared in the statement .T h e n ,t h ev a r i a b l e s
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 17

Chapter 2 Reading Data into SAS - STAT1303 Data Management...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online