SAS Input Method | SAS Input Statements
Stay updated with latest technology trends
Join DataFlair on Telegram!!
In last SAS Tutorial, we saw SAS Numeric Format. Here, we will see SAS Input Method/ SAS Input Statements. Moreover, we will discuss the different types of input methods in SAS Programming: Column Input, Formatted Input, and List input Methods in SAS to display our data. At last, we discuss examples of this SAS Input Method.
2. SAS Input Method
The form of your DATA step’s SAS Input Methods/ Statement depends on how the data values that you are trying to read in are arranged. If all of the data values are standard numeric or character values that are arranged in neatly defined columns as they are here below:
Then the data values can be read in using column input.
If the data values are arranged in neatly defined columns but contain some non-standard characters, such as the dollar sign ($) here:
Then the data values must be read in using formatted input.
And, if the data values are not arranged in neatly defined columns, but are separated by at least one space and contain no special characters, as they are here:
Then the data values must be read in using list input.
3. Types of Input Methods in SAS
Here, we discuss three types of SAS Input statements, let’s discuss one by one:
a. Column Input
Column input – SAS Input Method, allows you to read variable values that occupy the same columns within each record. As you know, to use column input, we simply list the variable names in the INPUT statement, immediately following each variable name with its corresponding column positions in each of the data lines.
For example, if an employee name contains maximum 6 characters and each employee name starts at 9th column, then the column width for employee name variable will be 9-15.
Column SAS Input Method Example-
Here are the important points to recall about SAS column input Method:
- When using column input, missing values can be left as blank.
- Column input uses the columns specified to determine the length of its character variables. Thereby allowing character values to exceed the default 8 characters and to have spaces.
- Spaces are not required between the data values.
b. Formatted Input
Formatted Input – SAS Input Method, the fundamental difference between column input and formatted input is that column input is only appropriate for reading standard numeric data. While formatted input allows us to read both standard and nonstandard numeric data. That is, formatted input combines the features of column input with the ability to read nonstandard data values.
Formatted SAS Input Method Example-
The @n absolute pointer control tells SAS to move the input pointer to a specific column number n. For example, the INPUT statement tells SAS to move the input pointer to column 18 before starting to read the values for the l_name variable. And, the +n relative pointer control tells SAS to move the input pointer forward n columns to a column number that is relative to the current position. For example, the INPUT statement tells SAS, after reading the values for the l_name variable, to move the input pointer 3 positions to the right before starting to read the values for the height variable.
c. List Input
List Input – SAS Input Method, if the data values that you are trying to read into a SAS data set are not arranged in neatly defined columns. But are separated by at least one space and contain no special characters, then you must use list input. To use list input, you simply place your desired variable names in your INPUT statement in the same order that your data fields appear in your input data file.
List SAS Input Method Example-
Although list input might be the easiest input style to use, it does have several limitations, including:
- Fields must be separated by at least one blank.
- Fields must be read in order from left to right.
- You cannot skip or re-read fields.
- Missing values must be represented by a placeholder such as a period(.).
- Although the width of a field can be greater than eight columns, both character and numeric variables have a default length of 8 bytes. Character values that are longer than eight characters are truncated.
- Data must be in standard character or numeric format.
Hence, today we learned about What is SAS Input Method/ SAS Input Statements, different types of SAS input method: Column Input, Formatted Input, and List Input Methods in SAS Programming that we can use while writing our SAS program. In conclusion, our dataset might have different requirements sometimes, sometimes our data might be simple. So, we can use List input method, sometimes, we might want to add special characters to the dataset. So, a different input method can be used. This was all about the different types of SAS input method. Post your doubts or queries in the comments section below.
Related Topic- SAS Environment Setup