Input Methods in SAS

Last updated on Dec 13 2021
Vaidehi Reddy

Table of Contents

Input Methods in SAS

The input methods are used to read the raw data. The raw data may be from an external source or from in stream datalines. The input statement creates a variable with the name that you assign to each field. So you have to create a variable in the Input Statement. The same variable will be shown in the output of SAS Dataset. Below are different input methods available in SAS.

  • List Input Method
  • Named Input Method
  • Column Input Method
  • Formatted Input Method

The details of each input method is described as below.

List Input Method

In this method the variables are listed with the data types. The raw data is carefully analysed so that the order of the variables declared matches the data. The delimiter (usually space) should be uniform between any pair of adjacent columns. Any missing data will cause problem in the output as the result will be wrong.

Example

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

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;

On running the above code we get the following output.

image001 11
output

Named Input Method

In this method the variables are listed with the data types. The raw data is modified to have variable names declared in front of the matching data. The delimiter (usually space) should be uniform between any pair of adjacent columns.

Example

The following code and the output show the use of 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;

On running the bove code we get the following output.

image001 11
Input

Column Input Method

In this method the variables are listed with the data types and width of the columns which specify the value of the single column of data. For example if an employee name contains maximum 9 characters and each employee name starts at 10th column, then the column width for employee name variable will be 10-19.

Example

Following code shows the use of Column Input Method.

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 above code, it produces following result −

image002 15
code

Formatted Input Method

In this method the variables are read from a fixed starting point until a space is encountered. As every variable has a fixed starting point, the number of columns between any pair of variables becomes the width of the first variable. The character ‘@n’ is used to specify the starting column position of a variable as the nth column.

Example

The following code shows the use of Formatted Input Method

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 above code, it produces following result −

image002 14
Named

So, this brings us to the end of blog. This Tecklearn ‘Input Methods in SAS’ blog helps you with commonly asked questions if you are looking out for a job in SAS. If you wish to learn SAS and build a career in Data Analytics domain, then check out our interactive, SAS Training for SAS BASE Certification Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

https://www.tecklearn.com/course/sas-training-for-sas-base-certification/

SAS Training for SAS BASE Certification Training

About the Course

SAS Certification Training is intended to make you an expert in SAS programming and Analytics. You will be able to analyse and write SAS code for real problems, learn to use SAS to work with datasets, perform advanced statistical techniques to obtain optimized results with Advanced SAS programming.  In this SAS online training course, you will also learn SAS macros, Machine Learning, PROC SQL, procedure, statistical analysis and decision trees. You will also work on real-life projects and prepare for the SAS Certified Base Programmer certification exam. Upon the completion of this SAS online training, you will have enough proficiency in reading spreadsheets, databases, using SAS functions for manipulating this data and debugging it.

Why Should you take SAS Training?

  • The average salary for a Business Intelligence Developer skilled in SAS is $100k (PayScale salary data)
  • SAS, Google, Facebook, Twitter, Netflix, Accenture & other MNCs worldwide are using SAS for their Data analysis activities and advance their existing systems.
  • SAS is a Leader in 2017 Gartner Magic Quadrant for Data Science Platform.

What you will Learn in this Course?

Introduction to SAS 

  • Introduction to SAS
  • Installation of SAS
  • SAS windows
  • Working with data sets
  • Walk through of SAS windows like output, search, editor etc

SAS Enterprise Guide

  • How to read and subset the data sets
  • SET Statement
  • Infile and Infile Options
  • SAS Format -Format Vs Informat

SAS Operators and Functions

  • Using Variables
  • Defining and using KEEP and DROP statements
  • Output Statement
  • Retain Statement
  • SUM Statement

Advanced SAS Procedures

  • PROC Import
  • PROC Print
  • Data Step Vs Proc
  • Deep Dive into Proc

Customizing Datasets

  • SAS Arrays
  • Useful SAS Functions
  • PUT/INPUT Functions
  • Date/Time Functions
  • Numeric Functions
  • Character Functions

SAS Format and SAS Graphs

  • SAS Format statements
  • Understanding PROC GCHART, various graphs, bar charts: pie, bar

Sorting Techniques

  • NODUP
  • NODUKEY
  • NODUP Vs NODUKEY

Data Transformation Function

  • Character functions, numeric functions and converting variable type
  • Use functions in data transformation

Deep Dive into SAS Procedures, Functions and Statements

  • Find Function
  • Scan Function
  • MERGE Statement
  • BY Statement
  • Joins
  • Procedures Vs Function
  • Where Vs If
  • What is Missover
  • NMISS
  • CMISS

PROC SQL

  • SELECT statement
  • Sorting of Data
  • CASE expression
  • Other SELECT statement clauses
  • JOINS and UNIONS

Using SAS Macros

  • Benefits of SAS Macros
  • Macro Variables
  • Macro Code Constituents and Macro Step
  • Positional Parameters to Macros

Got a question for us? Please mention it in the comments section and we will get back to you.

 

0 responses on "Input Methods in SAS"

Leave a Message

Your email address will not be published. Required fields are marked *