INPUT Function


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

Category: Special

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 suppresses 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

If the INPUT function returns a 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 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 .;     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:

  •   y=input(x,?? 2.);  
  •   y=input(x,? 2.); _error_=0;  

See Also

Functions:

  • 'INPUTC Function' on page 594

  • 'INPUTN Function' on page 596

  • 'PUT Function' on page 754

  • 'PUTC Function' on page 756

  • 'PUTN Function' on page 758

Statements:

  • 'INPUT Statement' on page 1245




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net