The INFILE Statement. Reading files into SAS from an outside source: A Very Useful Tool!.
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
Reading files into SAS from an outside source:A Very Useful Tool!
In addition to coming from different sources, the data may be delimited by spaces, tabs, or commas. There are codes to tell SAS what type of data it will be reading into the Editor.
The program you will use to read in a data file will follow this basic format, with slight variations:
DATAname of data set;
INFILE‘C:\location and name of file’ ;
INPUTvar1 var2 etc.;
Let’s try a couple of examples.
This will be the simplest type of data set you could encounter. Download the file called relief.txt, and save it to your hard drive where you will be able to easily locate it.
Open SAS and type the following code into your Editor window, keeping in mind that the path to the file may be different on your computer:
INFILE‘C:\Documents and Settings\My Documents\relief.txt’ ;
INPUT group $ time;
TITLE‘Reading in Data from an External File’ ;
PROC PRINT DATA = relieftime;
Check your log for valuable information. It tells you how many observations were read into SAS, and you can see if you are missing any data.
You will also encounter comma-separated value (csv) files, which are often created using Excel. To read in this type of data, you will need to use the DSD option in your SAS code.
Save the file about blood pressure (bp.csv) to your hard drive, then type the following code into your Editor window, keeping in mind the path to your file may be different from the example.
Before you read the file into SAS, open it and look at the format. Notice that first row contains variable names and there are a few missing values. We will address that using various SAS statements.
Other types of data may be tab delimited, and this is specified in the dlm option. We use the statement dlm = ’09’x. (’09’x is the hexadecimal representation of the tab character, but you don’t need to know that; it’s basically the technical way of specifying TAB as the delimiter.)
Download the file aplastic.txt, open it to see that the data begin on the first line, then read the file into SAS.
These are just a few examples of the most common types of files you may encounter when reading in an external data file into SAS using the INFILE statement.
This skill will be valuable for future tutorials and homework assignments.
Here are some helpful links for more info:
UCLA Academic Technology Services
University of Michigan Software Help
University at Albany CSDA