Previous Page | Next Page

The FORMAT Procedure

INVALUE Statement


Creates an informat for reading and converting raw data values.
See also: The section on informats in SAS Language Reference: Dictionary for documentation on informats supplied by SAS.
Featured in: Converting Raw Character Data to Numeric Values.

INVALUE <$>name <(informat-option(s))>
<value-range-set(s)>;

Task Option
Specify the default length of the informat. DEFAULT=
Specify a fuzz factor for matching values to a range. FUZZ=
Specify a maximum length for the informat. MAX=
Specify a minimum length for the informat. MIN=
Store values or ranges in the order that you define them. NOTSORTED
Left-justify all input strings before they are compared to ranges. JUST
Uppercase all input strings before they are compared to ranges. UPCASE


Required Arguments

name

names the informat that you are creating.

Requirement: The name must be a valid SAS name. A numeric informat name can be up to 31 characters in length; a character informat name can be up to 30 characters in length and cannot end in a number. If you are creating a character informat, then use a dollar sign ($) as the first character. Adding the dollar sign to the name is why a character informat is limited to 30 characters.
Restriction: A user-defined informat name cannot be the same as an informat name that is supplied by SAS.
Interaction: The maximum length of an informat name is controlled by the VALIDFMTNAME= SAS system option. See SAS Language Reference: Dictionary for details on VALIDFMTNAME=.
Tip: Refer to the informat later by using the name followed by a period. However, do not use a period after the informat name in the INVALUE statement.
Tip: When SAS prints messages that refer to a user-written informat, the name is prefixed by an at sign (@). When the informat is stored, the at sign is prefixed to the name that you specify for the informat. The addition of the at sign to the name is why the name is limited to 31 or 30 characters. You need to use the at sign only when you are using the name in an EXCLUDE or SELECT statement; do not prefix the name with an at sign when you are associating the informat with a variable.

Options

The following options are common to the INVALUE, PICTURE, and VALUE statements and are described in Informat and Format Options:

DEFAULT=length

FUZZ= fuzz-factor

MAX=length

MIN=length

NOTSORTED

In addition, you can use the following options:

JUST

left-justifies all input strings before they are compared to the ranges.

UPCASE

converts all raw data values to uppercase before they are compared to the possible ranges. If you use UPCASE, then make sure the values or ranges you specify are in uppercase.

value-range-set(s)

specifies raw data and values that the raw data will become. The value-range-set(s) can be one or more of the following:

value-or-range-1 <..., value-or-range-n>=informatted-value|[existing-informat]

The informat converts the raw data to the values of informatted-value on the right side of the equal sign.

informatted-value

is the value you want the raw data in value-or-range to become. Use one of the following forms for informatted-value:

'character-string'

is a character string up to 32,767 characters long. Typically, character-string becomes the value of a character variable when you use the informat to convert raw data. Use character-string for informatted-value only when you are creating a character informat. If you omit the single or double quotation marks around character-string, then the INVALUE statement assumes that the quotation marks are there.

For hexadecimal literals, you can use up to 32,767 typed characters, or up to 16,382 represented characters at two hexadecimal characters per represented character.

number

is a number that becomes the informatted value. Typically, number becomes the value of a numeric variable when you use the informat to convert raw data. Use number for informatted-value when you are creating a numeric informat. The maximum for number depends on the host operating environment.

_ERROR_

treats data values in the designated range as invalid data. SAS assigns a missing value to the variable, prints the data line in the SAS log, and issues a warning message.

_SAME_

prevents the informat from converting the raw data as any other value. For example, the following GROUP. informat converts values 01 through 20 and assigns the numbers 1 through 20 as the result. All other values are assigned a missing value.

   invalue group 01-20= _same_
                 other= .;
existing-informat

is an informat that is supplied by SAS or a user-defined informat. The informat you are creating uses the existing informat to convert the raw data that match value-or-range on the left side of the equal sign. If you use an existing informat, then enclose the informat name in square brackets (for example, [date9.]) or with parentheses and vertical bars, for example (|date9.|). Do not enclose the name of the existing informat in single quotation marks.

value-or-range

See Specifying Values or Ranges.

Consider the following examples:

  • The $GENDER. character informat converts the raw data values F and M to character values '1' and '2':

    invalue $gender 'F'='1'
                    'M'='2';

    The dollar sign prefix indicates that the informat converts character data.

  • When you are creating numeric informats, you can specify character strings or numbers for value-or-range. For example, the TRIAL. informat converts any character string that sorts between A and M to the number 1 and any character string that sorts between N and Z to the number 2. The informat treats the unquoted range 1-3000 as a numeric range, which includes all numeric values between 1 and 3000:

       invalue trial 'A'-'M'=1
                     'N'-'Z'=2
                      1-3000=3;
  • The CHECK. informat uses _ERROR_ and _SAME_ to convert values of 1 through 4 and 99. All other values are invalid:

       invalue check 1-4=_same_
                      99=.
                   other=_error_;

    If you use a numeric informat to convert character strings that do not correspond to any values or ranges, then you receive an error message.

Previous Page | Next Page | Top of Page