Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

SAS Input input method


May 26, 2021 SAS


Table of contents


The input method is used to read the original data. T he original data can come from an external source or from a streaming data. T he input statement creates a variable whose name is assigned to each field. S o you have to create a variable in the input statement. T he same variable appears in the output of the SAS dataset. T he following are the different input methods available in the SAS.

  • The list input method
  • Name the input method
  • Column input method
  • Format the input method

The details of each input method are described below.

List input method

In this method, variables are listed with the data type. A nalyze the raw data carefully so that the order of the declared variables matches the data. S eparators (usually spaces) should be consistent between any pair of adjacent columns. A ny lost data will cause problems in the output because the results will be wrong.

Cases

The following code and output shows the use of list input methods.

DATA TEMP;
INPUT   EMPID ENAME $ DEPT $ ;
DATALINES;
1 Rick  IT
2 Dan  OPS
3 Tusar  IT
4 Pranab  OPS
5 Rasmi  FIN
;
PROC PRINT DATA=TEMP;
RUN;

While running the bove code, we get the following output.

SAS Input input method

Name the input method

In this method, variables are listed with the data type. T he original data is modified to declare the variable name before the matching data. S eparators (usually spaces) should be consistent between any pair of adjacent columns.

Cases

The following code and output display uses a named input method.

DATA TEMP;
INPUT   
EMPID= ENAME= $ DEPT= $ ;
DATALINES;
EMPID=1 ENAME= Rick  DEPT= IT
EMPID=2 ENAME= Dan  DEPT= OPS
EMPID=3 ENAME= Tusar  DEPT= IT
EMPID=4 ENAME= Pranab  DEPT= OPS
EMPID=5 ENAME= Rasmi  DEPT= FIN
;
PROC PRINT DATA=TEMP;
RUN;

While running the bove code, we get the following output.

SAS Input input method SAS Input input method

Column input method

In this method, the data type and column width listed by the variable specify the value of the single-column data. F or example, if an employee name contains up to 9 characters, and each employee name starts in column 10, the column width of the employee name variable will be 10-19.

Cases

The following code shows how to use column input.

DATA TEMP;
INPUT   EMPID 1-3 ENAME $ 4-12 DEPT $ 13-16;
DATALINES;
14 Rick     IT 
241Dan      OPS 
30 Sanvi    IT 
410Chanchal OPS 
52 Piyu     FIN 
;
PROC PRINT DATA=TEMP;
RUN;

When we execute the code above, it produces the following results:

SAS Input input method

Format the input method (the only way an input statement can read non-standard data).

In this method, the variable is read from a fixed starting point until a space is encountered. B ecause each variable has a fixed starting point, the number of columns between any pair of variables becomes the width of the first variable. T he character "@n" specifies that the variable's starting column position is column n.

Cases

The following code shows the use of formatted input methods

DATA TEMP;
INPUT   @1 EMPID $ @4 ENAME $ @13 DEPT $ ;
DATALINES;
14 Rick     IT 
241 Dan      OPS 
30 Sanvi    IT 
410 Chanchal OPS 
52 Piyu     FIN 
;
PROC PRINT DATA=TEMP;
RUN;

When we execute the code above, it produces the following results:

SAS Input input method