Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Language Reference

INPUT Statement

inputs data

INPUT <variables> <informats> <record-directives> <positionals>;

where the clauses and options are explained below.

You can use the INPUT statement to input records from the current input file, placing the values into IML variables. The INFILE statement sets up the current input file. See Chapter 7, "File Access,", for details.

The INPUT statement contains a sequence of arguments that include the following:

variables
specify the variable or variables you want to read from the current position in the record. Each variable can be followed immediately by an input format specification.

informats
specify an input format. These are of the form w.d or $w. for standard numeric and character informats, respectively, where w is the width of the field and d is the decimal parameter, if any. You can also use a SAS format of the form NAMEw.d, where NAME is the name of the format. Also, you can use a single $ or & for list input applications. If the width is unspecified, the informat uses list-input rules to determine the length by searching for a blank (or comma) delimiter. The special format $RECORD. is used for reading the rest of the record into one variable. For more information on formats, refer to SAS Language Reference: Dictionary.

Record holding is always implied for RECFM=N binary files, as if the INPUT statement has a trailing @ sign. For more information, see Chapter 7, "File Access."

Examples of valid INPUT statements are shown below:
   input x y;
   input @1 name $ @20 sex $ @(20+2) age 3.;

   eight=8;
   input >9 <eight  number2 ib8.;
Below is an example using binary input:
   proc iml;
      file 'out2.dat' recfm=n ;
      number=499; at=1;
      do i = 1 to 5;
         number=number+1;
         put >at number ib8.; at=at+8;
      end;
      closefile 'out2.dat';

      infile 'out2.dat' recfm=n;
      size=8;     /* 8 bytes */
      do pos=1 to 33 by size;
         input >pos number ib8.;
         print number;
      end;


record-directives
are used to advance to a new record. Record-directives are the following:

holding @ sign
is used at the end of an INPUT statement to instruct IML to hold the current record so that you can continue to read from the record with later INPUT statements. Otherwise, IML automatically goes to the next record for the next INPUT statement.

/
advances to the next record.

> operand
specifies that the next record to be read starts at the indicated byte position in the file (for RECFM= N files only). The operand is a literal number, a variable name, or an expression in parentheses.

< operand
instructs IML to read the indicated number of bytes as the next record. The record directive must be specified for binary files (RECFM=N). The operand is a literal number, a variable name, or an expression in parentheses.

positionals
instruct PROC IML to go to a specific column on the record. The positionals are the following:
@ operand
instructs IML to go to the indicated column, where operand is a literal number, a variable name, or an expression in parentheses. For example, @30 means to go to column 30. The operand can also be a character operand when pattern searching is needed. For more information, see Chapter 7, "File Access."

+ operand
specifies to skip the indicated number of columns. The operand is a literal number, a variable name, or an expression in parentheses.

Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Top
Top

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