SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Reading Free-Format Data
Lesson Summary

 

This page contains


I. Text Summary

To go to the page where a task, programming feature, or concept was presented, select a link.

Free-Format Data
External files can contain raw data that is free-format; that is, the data is not arranged in fixed fields. The fields can be separated by blanks, or some other delimiter, such as commas.

Using List Input
Free-format data can easily be read with list input because you do not need to specify column locations of the data. You simply list the variable names in the same order as the corresponding raw data fields. You must distinguish character variables from numeric variables by using the dollar ($) sign.

When characters other than blanks are used to separate the data values, you can specify the field delimiter by using the DLM= option in the INFILE statement.

In its simplest form, list input places several limitations on the types of data that can be read.

Reading Missing Values
If your data contain missing values at the end of a record, you can use the INFILE statement with the MISSOVER option to prevent the SAS System from going to the next record to find the missing values.

If your data contains missing values at the beginning or in the middle of a record, you must edit the file so that a period (.) holds the place of the missing value.

Changing the Length of Character Values
You can change the length of character variables by using the LENGTH statement. The LENGTH statement enables you to use list input to read names that are longer than eight characters without truncating them.

Because variable attributes are defined when the variable is first encountered in the DATA step, the LENGTH statement precedes the INPUT statement and defines both the length and type of the variable.

When you use the LENGTH statement, it is not necessary to specify the variable type again in the INPUT statement.

Modifying List Input
Modified  list input may be used to read the values which contain embedded blanks and nonstandard values. Modified list input uses two format modifiers:

  • the ampersand (&) modifier enables you to read character values that contain single embedded blanks
  • the colon (:) modifier enables you to read nonstandard data values and character values longer than eight characters without embedded blanks.

It's important to remember that informats work differently in modified list input than they do in formatted input.

Mixing Input Styles
With some file layouts, you may need to mix input styles in the same INPUT statement in order to read the data correctly.


II. Syntax

To go to the page where a statement or option was presented, select a link.

LIBNAME libref  'SAS-data-library';
FILENAME fileref 'filename';
DATA SAS-data-set;
       INFILE raw-data-file <DLM='delimiter'> <MISSOVER>;
       LENGTH variable $ length;
       INPUT variable <$>   <&|:><informat>;
RUN;
PROC PRINT DATA=SAS-data-set;
RUN;


III. Sample Program
     libname perm 'c:\records\data';
     filename credit 'c:\records\credit.dat';
     data perm.carduse;
        infile credit dlm='*' missover;
        length LastName $ 14;
        input lastname $ Gender $ Age CardType $ 
              Total : comma.;
     run;
     proc print data=perm.carduse;
     run; 


IV. Points to Remember
  • When you use list input, fields must be separated by at least one blank or other delimiter.

  • Fields must be read in order, left to right. You cannot skip or reread fields.

  • Use a LENGTH statement to avoid truncating character values longer than eight characters.

  • In formatted input, the informat determines both the length of character variables and the number of columns to be read. The same number of columns are read from each record.

  • The informat in modified list input determines only the length of the variable value, not the number of columns to be read.


back||next

 

Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement