Chapter Contents

Previous

Next
INFORMAT

INFORMAT



Associates informats with variables

Valid: in a DATA step or PROC step
Category: Information
Type: Declarative


Syntax
Arguments
Details
The Basics
How SAS Treats Variables when You Assign Informats with the INFORMAT Statement
Comparisons
Examples
Example 1: Specifying Default Informats
Example 2: Specifying Numeric and Character Informats
Example 3: Removing an Informat
See Also

Syntax

INFORMAT variable(s) <informat>
<DEFAULT=default-informat>;

Arguments

variable
names one or more variables to associate with an informat. You must specify at least one variable.
Tip: To disassociate an informat from a variable, use the variable's name in an INFORMAT statement without specifying an informat. Place the INFORMAT statement after the SET statement. See Removing an Informat.

informat
specifies the informat for reading the values of the variables that are listed in the INFORMAT statement.
Tip: Informats that are associated with variables by using an INFORMAT statement behave like informats that you specify with a colon (:) modifier in an INPUT statement. SAS reads the variables by using list input with an informat. For example, you can use the : modifier with an informat to read character values that are longer than eight bytes, or numeric values that contain nonstandard values. For details, see INPUT, List .
See Also: Informats by Category
Featured in: Specifying Numeric and Character Informats

DEFAULT= default-informat
specifies a temporary default informat for reading values of the variables that are listed in the INFORMAT statement. These default informats apply only to the current DATA step.

A DEFAULT= informat specification applies to

Note:   When you use the DEFAULT= option on the INFORMAT statement, SAS reads values as formatted input, regardless of the style of input that you specify on the INPUT statement.  [cautionend]
Default: If you omit DEFAULT=, SAS uses w.d as the default numeric informat and $w. as the default character informat.
Tip A DEFAULT= specification can occur anywhere in an INFORMAT statement. It can specify either a numeric default, a character default, or both.
Featured in: Specifying Default Informats


Details

The Basics

An INFORMAT statement in a DATA step permanently associates an informat with a variable. You can specify standard SAS informats or user-written informats, previously defined in PROC FORMAT. A single INFORMAT statement can associate the same informat with several variables, or it can associate different informats with different variables. If a variable appears in multiple INFORMAT statements, SAS uses the informat that is assigned last.

CAUTION:
Because an INFORMAT statement defines the length of previously undefined character variables, you can truncate the values of character variables in a DATA step if an INFORMAT statement precedes a SET statement.   [cautionend]

How SAS Treats Variables when You Assign Informats with the INFORMAT Statement

Informats that are associated with variables by using the INFORMAT statement behave like informats that are used with modified list input. SAS reads the variables by using the scanning feature of list input, but applies the informat. In modified list input, SAS

If you have coded the INPUT statement to use another style of input, such as formatted input or column input, that style of input is not used when you use the INFORMAT statement.


Comparisons


Examples

Example 1: Specifying Default Informats

This example uses an INFORMAT statement to associate a default numeric informat and a default character informat:

data tstinfmt;
   informat default=3.1 default=$char4.;
   input x1-x10 name $;
   put x1-x10 name;
   datalines;
111222333444555666777888999100Johnny
;
The PUT statement produces this result :
----+----1----+----2----+----3----+----4----+----5----+
11.1 22.2 33.3 44.4 55.5 66.6 77.7 88.8 99.9 10 John

Example 2: Specifying Numeric and Character Informats

This example associates a character informat and a numeric informat with SAS variables. Although the character variables do not fully occupy 15 column positions, the INPUT statement reads the data records correctly by using modified list input:

data name;
   informat FirstName LastName $15. n1 6.2 n2 7.3;
   input firstname lastname n1 n2;
   datalines;
Alexander Robinson 35 11
;

proc contents data=name;
run;

proc print data=name;
run;

The following output shows a partial listing from PROC CONTENTS, as well as the report PROC PRINT generates.

                         The SAS System                        3

                       CONTENTS PROCEDURE

      -----Alphabetic List of Variables and Attributes-----
 
        #    Variable     Type    Len    Pos    Informat
        ------------------------------------------------
        1    FirstName    Char     15     16    $15.    
        2    LastName     Char     15     31    $15.    
        3    n1           Num       8      0    6.2     
        4    n2           Num       8      8    7.3     
                         The SAS System                        4

         OBS    FirstName    LastName     n1       n2

          1     Alexander    Robinson    0.35    0.011


Example 3: Removing an Informat

This example disassociates an existing informat. The order of the INFORMAT and SET statements is important.

data rtest;
   set rtest;
   informat x;
run;

See Also

Statements:

ATTRIB
INPUT
INPUT, List


Chapter Contents

Previous

Next

Top of Page

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