- SAS Tutorial
- SAS - Home
- SAS - Overview
- SAS - Environment
- SAS - User Interface
- SAS - Program Structure
- SAS - Basic Syntax
- SAS - Data Sets
- SAS - Variables
- SAS - Strings
- SAS - Arrays
- SAS - Numeric Formats
- SAS - Operators
- SAS - Loops
- SAS - Decision Making
- SAS - Functions
- SAS - Input Methods
- SAS - Macros
- SAS - Dates & Times

- SAS Data Set Operations
- SAS - Read Raw Data
- SAS - Write Data Sets
- SAS - Concatenate Data Sets
- SAS - Merging Data Sets
- SAS - Subsetting Data Sets
- SAS - Sort Data Sets
- SAS - Format Data Sets
- SAS - SQL
- SAS - Output Delivery System
- SAS - Simulations

- SAS Data Representation
- SAS - Histograms
- SAS - Bar Charts
- SAS - Pie Charts
- SAS - Scatterplots
- SAS - Boxplots

- SAS Basic Statistical Procedure
- SAS - Arithmetic Mean
- SAS - Standard Deviation
- SAS - Frequency Distributions
- SAS - Cross Tabulations
- SAS - T Tests
- SAS - Correlation Analysis
- SAS - Linear Regression
- SAS - Bland-Altman Analysis
- SAS - Chi-Square
- SAS - Fishers Exact Tests
- SAS - Repeated Measure Analysis
- SAS - One-Way Anova
- SAS - Hypothesis Testing

- SAS Useful Resources
- SAS - Quick Guide
- SAS - Useful Resources
- SAS - Questions and Answers
- SAS - Discussion

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# SAS - Basic Syntax

Like any other programming language, the SAS language has its own rules of syntax to create the SAS programs.

The three components of any SAS program - Statements, Variables and Data sets follow the below rules on Syntax.

## SAS Statements

Statements can start anywhere and end anywhere. A semicolon at the end of the last line marks the end of the statement.

Many SAS statements can be on the same line, with each statement ending with a semicolon.

Space can be used to separate the components in a SAS program statement.

SAS keywords are not case sensitive.

Every SAS program must end with a RUN statement.

## SAS Variable Names

Variables in SAS represent a column in the SAS data set. The variable names follow the below rules.

It can be maximum 32 characters long.

It can not include blanks.

It must start with the letters A through Z (not case sensitive) or an underscore (_).

Can include numbers but not as the first character.

Variable names are case insensitive.

### Example

# Valid Variable Names REVENUE_YEAR MaxVal _Length # Invalid variable Names Miles Per Liter #contains Space. RainfFall% # contains apecial character other than underscore. 90_high # Starts with a number.

## SAS Data Set

The DATA statement marks the creation of a new SAS data set. The rules for DATA set creation are as below.

A single word after the DATA statement indicates a temporary data set name. Which means the data set gets erased at the end of the session.

The data set name can be prefixed with a library name which makes it a permanent data set. Which means the data set persists after the session is over.

If the SAS data set name is omitted then SAS creates a temporary data set with a name generated by SAS like - DATA1, DATA2 etc.

### Example

# Temporary data sets. DATA TempData; DATA abc; DATA newdat; # Permanent data sets. DATA LIBRARY1.DATA1 DATA MYLIB.newdat;

## SAS File Extensions

The SAS programs, data files and the results of the programs are saved with various extensions in windows.

***.sas**− It represents the SAS code file which can be edited using the SAS Editor or any text editor.***.log**− It represents the SAS Log File it contains information such as errors, warnings, and data set details for a submitted SAS program.***.mht / *.html**−It represents the SAS Results file.***.sas7bdat**−It represents SAS Data File which contains a SAS data set including variable names, labels, and the results of calculations.

## Comments in SAS

Comments in SAS code are specified in two ways. Below are these two formats.

### *message; type comment

A comment in the form of ***message;** can not contain semicolons or unmatched quotation mark inside it. Also there should not be any reference to any macro statements inside such comments. It can span multiple lines and can be of any length.. Following is a single line comment example −

* This is comment ;

Following is a multiline comment example −

* This is first line of the comment * This is second line of the comment;

### /*message*/ type comment

A comment in the form of **/*message*/** is used more frequently and it can not be nested. But it can span multiple lines and can be of any length. Following is a single line comment example −

/* This is comment */

Following is a multiline comment example −

/* This is first line of the comment * This is second line of the comment */