Variables in SAS Explained

Last updated on Dec 13 2021
Vaidehi Reddy

Table of Contents

Variables in SAS Explained

In general variables in SAS represent the column names of the data tables it is analyzing. But it can also be used for other purpose like using it as a counter in a programming loop. In the current chapter we will see the use of SAS variables as column names of SAS Data Set.

SAS Variable Types

SAS has three types of variables as below −

Numeric Variables

This is the default variable type. These variables are used in mathematical expressions.

Syntax

INPUT VAR1 VAR2 VAR3;                     #Define numeric variables in the data set.

In the above syntax, the INPUT statement shows the declaration of numeric variables.

Example

INPUT ID SALARY COMM_PERCENT;

Character Variables

Character variables are used for values that are not used in Mathematical expressions. They are treated as text or strings. A variable becomes a character variable by adding a $ sing with a space at the end of the variable name.

Syntax

INPUT VAR1 $ VAR2 $ VAR3 $;            #Define character variables in the data set.

In the above syntax, the INPUT statement shows the declaration of character variables.

Example

INPUT FNAME $ LNAME $ ADDRESS $;

Date Variables

These variables are treated only as dates and they need to be in valid date formats. A variable becomes a date variable by adding a date format with a space at the end of the variable name.

Syntax

INPUT VAR1 DATE11. VAR2 MMDDYY10. ; #Define date variables in the data set.

In the above syntax, the INPUT statement shows the declaration of date variables.

Example

INPUT DOB DATE11. START_DATE MMDDYY10. ;

Use of Variables in SAS Program

The above variables are used in SAS program as shown in below examples.

Example

The below code shows how the three types of variables are declared and used in a SAS Program

DATA TEMP;
INPUT ID NAME $ SALARY DEPT $ DOJ DATE9. ;
FORMAT DOJ DATE9. ;
DATALINES;

1 Rick 623.3 IT 02APR2001

2 Dan 515.2 OPS 11JUL2012

3 Michelle 611 IT 21OCT2000

4 Ryan 729 HR 30JUL2012

5 Gary 843.25 FIN 06AUG2000

6 Tusar 578 IT 01MAR2009

7 Pranab 632.8 OPS 16AUG1998

8 Rasmi 722.5 FIN 13SEP2014

;

PROC PRINT DATA = TEMP;

RUN;

In the above example all the character variables are declared followed by a $ sign and the date variables are declared followed by a date format. The output of the above program is as below.

image001 23
Variables

Using the Variables

The variables are very useful in analyzing the data. They are used in expressions in which the statistical analysis is applied. Let’s see an example of analyzing the built-in Data Set named CARS which is present under Libraries → My Libraries → SASHELP. Double click on it to explore the variables and their data types.

image002 28
Using

Next, we can produce a summary statistics of some of these variables using the Tasks options in SAS studio. Go to Tasks -> Statistics -> Summary Statistics and double click it to open the window as shown below. Choose Data Set SASHELP.CARS and select the three variables – MPG_CITY, MPG_Highway and Weight under the Analysis Variables. Hold the Ctrl key while selecting the variables by clicking. Click run.

image003 20
run

Click on the results tab after the above steps. It shows the statistical summary of the three variables chosen. The last column indicates number of observations (records) used in the analysis.

image004 13
analysis

So, this brings us to the end of blog. This Tecklearn ‘Variables in SAS Explained’ 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 "Variables in SAS Explained"

Leave a Message

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