Chapter Contents

Previous

Next
INPUT

INPUT



Returns the value produced when a SAS expression that uses a specified informat expression is read

Category: Special


Syntax
Arguments
Details
Comparisons
Examples
Example 1: Converting Character Values to Numeric Values
Example 2: Using PUT and INPUT Functions
Example 3: Suppressing Error Messages
See Also

Syntax

INPUT(source, <? | ??>informat.)

Arguments

source
contains the SAS character expression to which you want to apply a specific informat.

? or ??
The optional question mark (?) and double question mark (??) format modifiers 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 supresses the invalid data message and, in addition, prevents the automatic variable _ERROR_ from being set to 1 when invalid data are read.

informat.
is the SAS informat that you want to apply to the source.


Details

The INPUT function enables you to read 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.


Comparisons

The INPUT function returns the value produced when a SAS expression is read 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 and then optionally stores that value in a variable.


Examples

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.;
      fmtsale=input(sale,comma9.);
      datalines;
   2,115,353
   ;

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.

   numdate=122591;
   chardate=put(numdate,z6.);
   sasdate=input(chardate,mmddyy6.);

Example 3: Suppressing Error Messages

In this example, the question mark (?) format 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 (??) format 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:


See Also

Functions:
INPUTC
INPUTN
PUT
PUTC
PUTN
Statements:
INPUT


Chapter Contents

Previous

Next

Top of Page

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