External Files. Definition CHAPTER 38

Similar documents
Chapter 3 Managing Results in Projects. Chapter Table of Contents

Permission Program. Support for Version 6 Only. Allowing SAS/SHARE Client Access to SAS Libraries or Files CHAPTER 40

Creating and Executing Stored Compiled DATA Step Programs

SAS File Management. Improving Performance CHAPTER 37

SAS I/O Engines. Definition. Specifying a Different Engine. How Engines Work with SAS Files CHAPTER 36

SAS Support for TELNET on Windows

Storing and Reusing Macros

SAS Catalogs. Definition. Catalog Names. Parts of a Catalog Name CHAPTER 32

Chapter 6 Creating Reports. Chapter Table of Contents

Chapter 25 PROC PARETO Statement. Chapter Table of Contents. OVERVIEW SYNTAX SummaryofOptions DictionaryofOptions...

Chapter 28 Saving and Printing Tables. Chapter Table of Contents SAVING AND PRINTING TABLES AS OUTPUT OBJECTS OUTPUT OBJECTS...

APPENDIX 2 Customizing SAS/ASSIST Software

SAS Data Libraries. Definition CHAPTER 26

Data Set Options. Specify a data set option in parentheses after a SAS data set name. To specify several data set options, separate them with spaces.

SAS/ASSIST Software Setup

APPENDIX 4 Migrating from QMF to SAS/ ASSIST Software. Each of these steps can be executed independently.

UNIX Spawner Program. Starting the UNIX Spawner Program CHAPTER 36

Introduction. LOCK Statement. CHAPTER 11 The LOCK Statement and the LOCK Command

Using Cross-Environment Data Access (CEDA)

Using Data Transfer Services

Optimizing System Performance

Data Representation. Variable Precision and Storage Information. Numeric Variables in the Alpha Environment CHAPTER 9

OS/390 Platform Examples

UNIX Platform Error Messages

Using MDP Extensions. What Is the Multidimensional Data Provider? CHAPTER 3

CHAPTER 13 Importing and Exporting External Data

Routing the SAS Log and SAS Procedure Output

from the source host, use the FTP put command to copy a file from the source host to the target host.

OS/2: SPX Access Method

Windows: SPX Access Method

Introduction to MDDBs

Alternative ODS HTML Statements for Running Examples in Different Operating Environments

Formats. Formats Under UNIX. HEXw. format. $HEXw. format. Details CHAPTER 11

Using the SQL Editor. Overview CHAPTER 11

CHAPTER 5 Macintosh: TCP/IP Access Method

Graphics. Chapter Overview CHAPTER 4

DBLOAD Procedure Reference

What Is a Communications Access Method? CHAPTER 1 Using Communications Access Methods

SAS. IT Service Level Management 2.1: Migration Documentation

Informats. Informats Under UNIX. HEXw. informat. $HEXw. informat. Details CHAPTER 13

QUEST Procedure Reference

Chapter 13 Multivariate Techniques. Chapter Table of Contents

The correct bibliographic citation for this manual is as follows: SAS Institute Inc Proc EXPLODE. Cary, NC: SAS Institute Inc.

Overview. CHAPTER 2 Using the SAS System and SAS/ ASSIST Software

Customizing Your SAS Session

Tasks Menu Reference. Introduction. Data Management APPENDIX 1

Using Dynamic Data Exchange

Chapter 14 Introduction to the FACTEX Procedure

Installation Instructions for SAS/ACCESS Interface to SAP BW

Chapter 27 Saving and Printing Graphics

Examples That Use Remote Objecting

SAS Web Infrastructure Kit 1.0. Overview, Second Edition

Locking SAS Data Objects

Chapter 23 Animating Graphs. Chapter Table of Contents ANIMATING SELECTION OF OBSERVATIONS ANIMATING SELECTED GRAPHS...347

SAS Web Infrastructure Kit 1.0. Overview

CHAPTER 7 Examples of Combining Compute Services and Data Transfer Services

Chapter 15 Mixed Models. Chapter Table of Contents. Introduction Split Plot Experiment Clustered Data References...

Macro Facility. About the Macro Facility. Automatic Macro Variables CHAPTER 14

Chapter 23 Introduction to the OPTEX Procedure

Choosing the Right Procedure

Routing Output. Producing Output with SAS Software CHAPTER 6

Chapter 9 Selected Examples. Queues with Reneging

Chapter 7 File Access. Chapter Table of Contents

The SERVER Procedure. Introduction. Syntax CHAPTER 8

SAS Forecast Server 3.1. Administrator s Guide to Installation and Configuration

OpenVMS Operating Environment

SAS. Installation Guide Fifth Edition Intelligence Platform

Introduction. Getting Started with the Macro Facility CHAPTER 1

SAS/ACCESS Interface to R/3

Using Unnamed and Named Pipes

The GTESTIT Procedure

Changes and Enhancements

Introduction. Understanding SAS/ACCESS Descriptor Files. CHAPTER 3 Defining SAS/ACCESS Descriptor Files

The EXPLODE Procedure

10 The First Steps 4 Chapter 2

CHAPTER 7 Using Other SAS Software Products

CV2ODBC Procedure. Overview. CV2ODBC Procedure Syntax APPENDIX 4

SAS Data Integration Studio 3.3. User s Guide

Batch Importing. Overview CHAPTER 4

SAS Component Language (SCL) Interface to Agent Services

Introduction. CHAPTER 3 Working in the SAS Windowing Environment

Administering SAS Enterprise Guide 4.2

DATA Step Debugger APPENDIX 3

SAS. Information Map Studio 3.1: Creating Your First Information Map

Allocating External Files

Changes and Enhancements

SCL Arrays. Introduction. Declaring Arrays CHAPTER 4

Functions and CALL Routines

Chapter 2 User Interface Features. networks Window. Drawing Panel

SAS 9.2 Foundation Services. Administrator s Guide

Changes and Enhancements

The GSLIDE Procedure. Overview. About Text Slides CHAPTER 27

SAS Publishing. Configure SAS. Forecast Server 1.4. Stored Processes

SAS AppDev Studio TM 3.4 Eclipse Plug-ins. Migration Guide

Licensing SAS DataFlux Products

SAS Clinical Data Integration 2.4

SAS Enterprise Guide 4.3

Procedures. PROC CATALOG CATALOG=<libref.>catalog <ENTRYTYPE=etype> <KILL>; CONTENTS <OUT=SAS-data-set> <FILE=fileref;>

Chapter 28 INSET Statement. Chapter Table of Contents

Changes and Enhancements

Transcription:

525 CHAPTER 38 External Files Definition 525 Referencing External Files Directly 526 Referencing External Files Indirectly 526 Referencing Many Files Efficiently 527 Referencing External Files with Other Access Methods 528 Working with External Files 529 Reading External Files 529 Writing to External Files 529 Processing External Files 530 Definition external files are files that are managed and maintained by your operating system, not by SAS. They contain data or text or are files in which you want to store data or text. They can also be SAS catalogs or output devices. Every SAS job creates at least one external file, the SAS log. Most SAS jobs create external files in the form of procedure output or output created by a DATA step. External files used in a SAS session can store input for your SAS job as: 3 records of raw data that you want to use as input to a DATA step 3 SAS programming statements that you want to submit to the system for execution. External files can also store output from your SAS job as: 3 a SAS log (a record of your SAS job) 3 a report written by a DATA step. 3 procedure output created by SAS procedures, including regular list output, and, beginning in Version 7, HTML and PostScript output from the Output Delivery System (ODS). The PRINTTO procedure also enables you to direct procedure output to an external file. For more information, see SAS Procedures Guide. See Chapter 16, SAS Output, on page 197 for more information about ODS. Note: Database management system (DBMS) files are a special category of files that can be read with SAS/ACCESS software. For more information on DBMS files, see Chapter 33, Accessing Data in a DBMS, on page 487 and the SAS/ACCESS documentation for your DBMS. 4

526 Referencing External Files Directly 4 Chapter 38 Operating Environment Information: Using external files with your SAS jobs entails significant operating-environment-specific information. Refer to the SAS documentation for your operating environment for more information. 4 Referencing External Files Directly To reference a file directly in a SAS statement or command, specify in quotation marks its physical name, which is the name by which the operating environment recognizes it, as shown in the following table: Table 38.1 Referencing External Files Directly External File Task Tool Example Specify the file that contains input data. Identify the file that the PUT statement writes to. Bring statements or raw data from another file into your SAS job and execute them. INFILE FILE %INCLUDE data weight; infile input-file ; input idno $ week1 week16; loss=week1-week16; file output-file ; if loss ge 5 and loss le 9 then put idno loss AWARD STATUS=3 ; else if loss ge 10 and loss le 14 then put idno loss AWARD STATUS=2 ; else if loss ge 15 then put idno loss AWARD STATUS=1 ; run; %include source-file ; Referencing External Files Indirectly If you want to reference a file in only one place in a program so that you can easily change it for another job or a later run, you can reference a filename indirectly. Use a statement, the function, or an appropriate operating system command to assign a fileref or nickname, to a file.* Note that you can assign a fileref to a SAS catalog that is an external file, or to an output device, as shown in the following table. * In some operating environments, you can also use the command & to assign a fileref.

External Files 4 Referencing Many Files Efficiently 527 Table 38.2 Referencing External Files Indirectly External File Task Tool Example a file that contains input data. a file for output data. a file that contains program statements. an output device. Specify the file that contains input data. Specify the file that the PUT statement writes to. Bring statements or raw data from another file into your SAS job and execute them. INFILE FILE %INCLUDE filename mydata input-file ; filename myreport output-file ; filename mypgm source-file ; filename myprinter <device-type> <host-options>; data weight; infile mydata; input idno $ week1 week16; loss=week1-week16; file myreport; if loss ge 5 and loss le 9 then put idno loss AWARD STATUS=3 ; else if loss ge 10 and loss le 14 then put idno loss AWARD STATUS=2 ; else if loss ge 15 then put idno loss AWARD STATUS=1 ; run; %include mypgm; Referencing Many Files Efficiently When you use many files from a single aggregate storage location, such as a directory or partitioned data set (PDS or MACLIB), you can use a single fileref, followed by a filename enclosed in parentheses, to access the individual files. This saves time by eliminating the need to type a long file storage location name repeatedly. It also makes changing the program easier later if you change the file storage location. The following table shows an example of assigning a fileref to an aggregate storage location:

528 Referencing External Files with Other Access Methods 4 Chapter 38 Table 38.3 Referencing Many Files Efficiently External File Task Tool Example aggregate storage location. Specify the file that contains input data. Specify the file that the PUT statement writes to. 1 Bring statements or raw data from another file into your SAS job and execute them. INFILE FILE %INCLUDE filename mydir directory-or-pds-name ; data weight; infile mydir(qrt1.data); input idno $ week1 week16; loss=week1-week16; file mydir(awards); if loss ge 5 then put idno loss AWARD STATUS=3 ; else if loss ge 10 then put idno loss AWARD STATUS=2 ; else if loss ge 15 then put idno loss AWARD STATUS=1 ; run; %include mydir(whole.program); 1 SAS creates a file that is named with the appropriate extension for your operating environment. Operating Environment Information: The CMS operating environment does not allow write access to an aggregate MACLIB. 4 Referencing External Files with Other Access Methods You can assign filerefs to external files that you access with the following access methods: 3 CATALOG 3 FTP 3 TCP/IP SOCKET 3 URL. Examples of how to use each method are shown in the following table:

External Files 4 Writing to External Files 529 Table 38.4 Referencing External Files with Other Access Methods External File Task Tool Example Assign a fileref to a SAS catalog that is an aggregate storage location. Assign a fileref to an external file accessed with FTP. Assign a fileref to an external file accessed by TCP/IP SOCKET in either client or server mode. Assign a fileref to an external file accessed by URL. with CATALOG specifier with FTP specifier with SOCKET specifier with URL specifier filename mycat catalog catalog <catalog-options>; filename myfile FTP external-file <ftp-options>; filename myfile SOCKET hostname: portno <tcpip-options>; or filename myfile SOCKET :portno SERVER <tcpip-options>; filename myfile URL external-file <url-options>; See SAS Language Reference: Dictionary for detailed information about each of these statements. Working with External Files Reading External Files The primary reason for reading an external file in a SAS job is to create a SAS data set from raw data. This topic is covered in Chapter 22, Reading Raw Data, on page 285. Writing to External Files You can write to an external file by using: 3 a SAS DATA step 3 the External File Interface (EFI) 3 the Export Wizard. When you use a DATA step to write a customized report, you write it to an external file. In its simplest form, a DATA step that writes a report looks like this: data _null_; set budget;

530 Processing External Files 4 Chapter 38 file your-file-name ; put variables-and-text; run; For examples of writing reports with a DATA step, see Chapter 22, Reading Raw Data, on page 285. If your operating environment supports a graphical user interface, you can use the EFI or the Export Wizard to write to an external file. The EFI is a point-and-click graphical interface that you can use to read and write data that is not in SAS software s internal format. By using the EFI, you can read data from a SAS data set and write it to an external file, and you can read data from an external file and write it to a SAS data set. See the SAS online Help for more information on the EFI. The Export Wizard guides you through the steps to read data from a SAS data set and write it to an external file. As a wizard, it is a series of windows that present simple choices to guide you through the process. See the SAS online Help for more information on the wizard. Processing External Files When reading data from or to a file, you can also use a DATA step to: 3 copy only parts of each record to another file 3 copy a file and add fields to each record 3 process multiple files in the same way in a single DATA step 3 create a subset of a file 3 update an external file in place 3 write data to a file that can be read in different computer environments 3 correct errors in a file at the bit level. For examples of using a DATA step to process external files, see Chapter 22, Reading Raw Data, on page 285.

Your Turn If you have comments or suggestions about SAS Language Reference: Concepts Version 8, please send them to us on a photocopy of this page or send us electronic mail. For comments about this book, please return the photocopy to SAS Institute Publications Division SAS Campus Drive Cary, NC 27513 email: yourturn@sas.com For suggestions about the software, please return the photocopy to SAS Institute Technical Support Division SAS Campus Drive Cary, NC 27513 email: suggest@sas.com

The correct bibliographic citation for this manual is as follows: SAS Institute Inc., SAS Language Reference: Concepts, Cary, NC: SAS Institute Inc., 1999. 554 pages. SAS Language Reference: Concepts Copyright 1999 SAS Institute Inc., Cary, NC, USA. ISBN 1 58025 441 1 All rights reserved. Printed in the United States of America. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, by any form or by any means, electronic, mechanical, photocopying, or otherwise, without the prior written permission of the publisher, SAS Institute, Inc. U.S. Government Restricted Rights Notice. Use, duplication, or disclosure of the software by the government is subject to restrictions as set forth in FAR 52.227 19 Commercial Computer Software-Restricted Rights (June 1987). SAS Institute Inc., SAS Campus Drive, Cary, North Carolina 27513. 1st printing, November 1999 SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. indicates USA registration. IBM, ACF/VTAM, AIX, APPN, MVS/ESA, OS/2, OS/390, VM/ESA, and VTAM are registered trademarks or trademarks of International Business Machines Corporation. indicates USA registration. Other brand and product names are registered trademarks or trademarks of their respective companies. The Institute is a private company devoted to the support and further development of its software and related services.