INPUT Function

Returns the value that is produced when SAS converts an expression using the specified informat.

Category: Special


Required Arguments


specifies a character constant, variable, or expression to which you want to apply a specific informat.

? or ??

specifies the optional question mark (?) and double question mark (??) modifiers that suppress the printing of both the error messages and the input lines when invalid data values are read. The ? modifier suppresses the invalid data message. The ?? modifier also suppresses the invalid data message and, in addition, prevents the automatic variable _ERROR_ from being set to 1 when invalid data are read.


is the SAS informat that you want to apply to the source. This argument must be the name of an informat followed by a period, and cannot be a character constant, variable, or expression.


If the INPUT function returns a character value to a variable that has not yet been assigned a length, by default the variable length is determined by the width of the informat.
The INPUT function enables you to convert the value of source by using a specified informat. The informat determines whether the result is numeric or character. Use INPUT to convert character values to numeric values or other character values.


The INPUT function returns the value produced when a SAS expression is converted using a specified informat. You must use an assignment statement to store that value in a variable. The INPUT statement uses an informat to read a data value. Storing that value in a variable is optional.
The INPUT function requires the informat to be specified as a name followed by a period and optional decimal specification. The INPUTC and INPUTN functions allow the informat to be specified as a character constant, variable, or expression.


Example 1: Converting Character Values to Numeric Values

This example uses the INPUT function to convert a character value to a numeric value and store it in another variable. The COMMA9. informat reads the value of the SALE variable, stripping the commas. The resulting value, 2115353, is stored in FMTSALE.
   data testin;
      input sale $9.;

Example 2: Using PUT and INPUT Functions

In this example, PUT returns a numeric value as a character string. The value 122591 is assigned to the CHARDATE variable. INPUT returns the value of the character string as a SAS date value using a SAS date informat. The value 11681 is stored in the SASDATE variable.

Example 3: Suppressing Error Messages

In this example, the question mark (?) modifier tells SAS not to print the invalid data error message if it finds data errors. The automatic variable _ERROR_ is set to 1 and input data lines are written to the SAS log.
   y=input(x,? 3.1);
Because the double question mark (??) modifier suppresses printing of error messages and input lines and prevents the automatic variable _ERROR_ from being set to 1 when invalid data are read, the following two examples produce the same result:
  • y=input(x,?? 2.);
  • y=input(x,? 2.); _error_=0;

See Also

INPUT Statement in SAS Statements: Reference