Getting Started with SAS

shashi
3 min readJul 19, 2020

Hello Everyone,

Welcome to my blog on Getting Started with SAS Programming. In this and upcoming blog I will try to explain everything related to SAS from basic to advanced. So stay tuned.

Let’s get started.

SAS Overview

SAS Program consists of two steps

  1. DATA Step and
  2. PROC Step or Procedure Steps

A SAS program can contain any number of DATA and PROC steps depending on the tasks performed.

The data steps end with the run statement and proc statements end with quit and others with run statements. If the run statement is not used, then the beginning of the new step continues with the data or proc statement.

The steps are counted as the number of data or proc segments.

Steps in SAS

The DATA step is the input source and it reads the data, processes it, generates the SAS table, and also performs data manipulations.

A PROC or procedure step processes a SAS table in a specific and predefined way. SAS has dozens of procedures that generate reports and graphs, managed data, or perform complex statistical analyses.

All statement ends with semicolons;

Steps Overview of SAS
Steps in SAS

Global Statements

The Global statements are kept outside the data and proc statements, they generally define the options for that SAS sessions. They don't need ‘run’ statements after them.

Writing code in SAS

The Spacing doesn't matter to SAS, as long as there is a semicolon between statements. We can write any keyword in any case as SAS is not case-sensitive.

Comments

Single line comments are written using “*” and end with a semicolon. Multiline comments are written as “/* comments*/”.

Accessing Data

1. Structured Data: Defined Rows and Columns, can be SAS Table, SQL table, MS Excel.
2. Unsturctured Data: JSON, weblogs, csv files

SAS Table

SAS Tables have defined rows and columns and have an extension of .sas7bdat There is a two-part to the SAS table:

  1. The descriptor portion often known as the header, contains information about the table metadata like table name, number of rows, date of creation, column name and attributes,
  2. The Data portion which is the rest of the row, stores data in columns.

SAS Table Terminology:

1. Table is also called a dataset.
2. Columns is also called a variable,
3. Row is also called an obseravtion.

These terms are interchangeable.

Required Column Attributes

A SAS column must have three attribute

1. Name:

- SAS Column names can be 1–32 characters long.

- Must start with a letter or underscore.

- Can contain any number of combination of letters, numbers and, underscores.

The Column name is stored in the same way you specify when you create the column. After the column is created we can reference them using the name in any case & even mixed cases are allowed.

2. Type:

- There are two types of columns in SAS: Character & Numeric

  • Numeric Columns can store only numeric values, which can include:

- A number from 0–9,

- A minus sign,

- A single decimal point and

- E for scientific notation.

Missing Numeric Characters are stored as a period

SAS Dates are a particular kind of numeric value. SAS stores date values as the number of days between January 1, 1960, and a specific date. Dates before January 1, 1960, are stored as negative values. This way of storing date values makes calculations and sorting possible. There are ways to display these values so they look like dates we can understand.

  • Character Columns can store letters, numbers, special characters, and blanks. Missing character columns are stored as space.

3. Length

- The column length is the length in bytes allocated to store the column values.

- The length is related to the column type.

- Numeric columns, by default, are always stored as 8 bytes, which is enough for about 16 significant digits.

- Character columns can be any length between 1 and 32,767 bytes, and one byte stores one character.

A Column length must have a length at least as long as the longest entry in the column.

--

--