## Introduction to SAS Commands

SAS full form is the Statistical Analysis System. It has been provided by the SAS Institute in the year 1970. It is the software which is used for doing the statistical analysis, graphing and presenting the data. In this, there are two categories to present and analyze the data that are DATA step and PROC step. DATA step is mainly used for providing the data management like reading the data, Data transformation and creating or removing the variables. PROC step used to perform the wide variety analysis on the data. There are various SAS commands available to achieve the presentation and analysis of data.

### Basic SAS Commands

**Proc Print:**It is used to view SAS data file in the output window.

**Example: **

proc print data= Grades;

Run;

**Proc contents**: It is used to check the content of the SAS Command data file in the output window

**Example:**

proc contents data=Grades;

Run;

**Proc means:**It is used to see the basic statistics of data. It provides the value of the mean, max, and min of the numeric values or variables.

**Example: **

proc means data= Grades;

Run;

**Proc Freq**: It is used to analyze the data and frequency of variables created and for tables

**Example:**

proc freq data=Grades;

Run;

**Example**:

proc freq data=Grades;

Tables a*b;

Run;

**Proc sort**: It is used to sort the SAS data file.

**Example**:

proc sort data=Gardes; Out= name by name;

Run;

**Proc reg**: It is used for one of the general purpose procedure for SAS regression analysis.

**Example:**

proc reg data= Grades;

Run;

**Proc gplot**: It is used to plot the two values or more on axes.

**Example**:

proc gplot data=Grades;

Plot a*b;

a = vertical axis,

b = horizontal axis;

Run;

**PROC transpose**: It is used to convert rows into columns in the data set.

**Example:**

proc transpose data= Grades out= Field;

By name; var result; id col;

Run;

**Proc Gchart:**It is used to create the pie chart histogram.

**Example:**

proc Gchart data=grades;

Vbar age;

Run;

**Proc report:**It is used to create the report from the data set.

**Example:**

proc report data=Grades;

Column A;

Define A / display;

Run;

### Intermediate SAS Commands

**Libname**: It is used to create the SAS Commands library.

**Example**:

Libname NewLib ‘C:\Grades’;

**Filename:**It is used to specify the external data file.

**Example:**

Filename AName ‘C:\Grades’;

**Infile**: It is the statement that used to read an external data file.

**Example:**

Filename AName ‘C:\Grades’;

DATA SAS;

INPUT A B;

Infile AName;

Run;

**If-Then:**It is the statement used to execute different functions.

**Example**:

DATA AB;

IF A>B then message=’A is greater’;

Else message=’B is greater’;

Run;

**Keep**: It is the statement used to keep the variable that is required in the data set.

**Example**:

Data New;

SET version;

Keep name year price;

Run;

**Label**: It is a function to change the label of the variable.

**Example**:

Data ABC;

Label text “Hello, world”;

Run;

**Length**: It is used to change the length of the variable.

**Example**:

Data ABC;

Length text $10.;

Run;

**Format**: It is used to change the format of the variable.

**Example:**

Data ABC;

Format date yymmdd10.;

Run;

**Input**: It is used to convert the character value into a numeric value.

**Example:**

Data ABC;

A = “ 10 ”;

B= input (a, best.);

Run;

**Log**: It is used to convert the numeric value into a logarithm.

**Example:**

Data ABC;

A = 10;

B = log(a);

Run;

### Advanced SAS Commands

**Mean, Min and Max**: It is used to compute the mean, minimum and maximum set of numeric values.

**Example:**

Data Mathdata;

A= 10;

B=20;

C= mean (a,b);

D= Min(a,b);

E= Max(a,b);

Run;

**Rename**: This SAS Commands is used to rename the variable.

**Example**:

Data mathdata;

A= 20;

Rename a= b;

Run;

**Square root/ Square**: It is used to calculate the square and the square root of the numeric value.

**Example**:

Data mathdata;

A= 4;

Square= a**2;

Sqroot = a**(1/2);

Run;

**Mathematical functions:**To perform basic mathematical functions.

**Example:**

Data mathdata;

Set Math;

Price = sum (of P1, P2);

Diff = D1 – D2;

M = M1 * M2;

Div= Div1 / Div2;

Run;

**Substr**: It is used to get the partial text from the text value.

**Example**:

Data Mathdata;

Text = “Hello World”;

Text1= substr(Text, 6, 2);

Run;

**Input and data line statement:**It is used to create the data set with specified content.

**Example:**

DATA ABC;

Input A B C;

DATALINES;

1 2 3

4 6 9

;

Run;

**Merge**: It is used to merge multiple data set into one.

**Example**:

Data ABC;

Merge name John;

By ID;

### Tips and Tricks to Use SAS Commands

- Think before programming, check all the criteria that need to cover.
- Keep it simple.
- Make the data sets easier to understand by putting the data that you need, helps in saving the disk space.
- Use functions for the data conversion.
- Avoid infinity means division by zero.
- Use Null when you do not need to create the data set.
- Assign the constant value to a variable in retain statement.
- Use NoEquals option on sorting which helps in saving the time and memory.

### Conclusion – SAS Commands

Everyone has its own way to achieve the end result, these can be the same or different for the different people. There are many ways to find one result and while using the SAS Commands software, one might get many ways to achieve the same result in different ways. It has been observed that more you learn and more you go through the documentation of SAS commands, the more benefit you will get to achieve the results and help in the long run.

The above mentioned SAS commands are mainly used in SAS software programming. The things are mainly covered around DATA and PROC. It is an easy tool or software to use and so that SAS commands, which are simple in writing mean writing the commands in simple English as you have already seen above commands. It is easy to use, learn and write.

### Recommended Articles

This has been a guide to SAS Commands. Here we have discussed basic as well as advanced SAS Commands and some immediate SAS Commands. You may also look at the following article to learn more –