CH9 - STAT1303A Data Management 9. More Data Input / Output...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: STAT1303A Data Management 9. More Data Input / Output 9 More Data Input / Output In Chapter 3, we have introduced the reading observations in to SAS. Basically, all those &les are saved in ASCII format. When the number of observations is small, they can be embedded into the SAS program as well. In this chapter, we focus on reading observations from external &les other than ASCII formats. Also, exporting SAS data sets to external &les is also considered. 9.1 Share data with other software 9.1.1 Read data from other software To read in delimiter &les, there are three methods in SAS 1. Statement INFILE with options DLM and DSD in the Data Step. 2. PROC IMPORT 3. IMPORT wizard Since the &rst method has been covered in Chapter 3, we do not repeat here for convenience. 9.1.1.1 PROC IMPORT / IMPORT wizard At the beginning, one should emphasize that PROC IMPORT and IMPORT wizard save time to write Data Step but lose ¬°exibility. Speci&cally, they share some advantages: & Scan the input data &le. & Determine the variables types which may be character or numeric automatically. & Assign proper lengths to character variables automatically. & Treat 2 consecutive delimiters as a missing value. & Read values enclosed by quotation marks. & Assign missing values to variables when it runs out of data one a line. Example 9.1. Suppose we import a comma-delimited (csv) &le name IMPORT.CSV by PROC IMPORT. Then, the following SAS codes are used: HKU STAT1303A (2009-10, Semester 1) 9 ¬° 1 STAT1303A Data Management 9. More Data Input / Output * Example 9.1 - import a csv file; proc import datafile=&D:\temp\import.csv& out=import dbms=csv replace; * overwrite existing data set; run; proc print data=import; run; proc contents data=import varnum; * print a list of the variables by their logical position in the data set; run; where option DATAFILE= speci&es the location and the name of the input &le, option OUT= speci&es the name of output SAS data set to be created, option DBMS=CSV speci&es the input &le in CSV format. In fact, SAS can support the other formats of the input &le. For example, Identi&er Input Data Source Extension Host Availability ACCESS Microsoft Access .mdb Microsoft Windows 2000 or 2002 table CSV delimited &le .csv OpenVMS Alpha, Unix (comma-separated Microsoft Windows values) DEF dBASE 5.0, IV, III+, .dbf Unix, Microsoft Windows and III &les DLM delimited &le (default .* OpenVMS Alpha, Unix, delimiter is a blank) Microsoft Windows EXCEL Excel 2000 or 2002 .xls Microsoft Windows spreadsheet Alternatively, we can read in the data &le by SAS IMPORT wizard. SAS IMPORT wizard is a series of menu-driven dialogue to de&ne the details for the import. 1. From menu File - > Import data, HKU STAT1303A (2009-10, Semester 1) 9 & 2 STAT1303A Data Management 9. More Data Input / Output 2. Select the &le type....
View Full Document

This document was uploaded on 05/04/2011.

Page1 / 11

CH9 - STAT1303A Data Management 9. More Data Input / Output...

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