SAS Tutorial for Beginners: What is & Programming Example
โก Smart Summary
SAS is a command-driven statistical software suite used for data analysis, business intelligence and predictive modeling. Its DATA and PROC steps, product suite, three-tier architecture and free academic editions are covered below.
What is SAS?
SAS is a command-driven statistical software suite widely used for statistical data analysis and visualization. The SAS full form is Statistical Analysis System. It allows you to use qualitative techniques and processes which help you to enhance employee productivity and business profits. SAS is also used for advanced analytics like business intelligence, crime investigation, and predictive analysis. SAS is commonly pronounced “sass.”
In SAS, data is extracted & categorized which helps you to identify and analyze data patterns. It is a software suite which allows you to perform advanced analysis, Business Intelligence, Predictive Analysis, and data management, so that you can operate effectively in competitive and changing business conditions. Moreover, SAS is platform independent, which means you can run SAS on any operating system, either Linux or Windows.
Compared to other BI tools, SAS provides extensive support to programmatically transform and analyze data, apart from using the drag and drop interface. This provides very granular control over data manipulation and analysis, which is its USP.
Why do we need SAS?
Let’s understand the need for SAS with a simple example:
Consider an e-commerce company that wants to know the buying patterns of its customers based on historical data. The company will have to consider thousands of records of multiple customers to reach a generalized insight.
The company may not have all the data required for the analysis. For example, if a customer did not buy a jacket, what were the factors that stopped them from buying it? This missing data could create errors in your analysis. How can we get rid of these problems? How can we handle this type of data?
If done manually, this task will require hundreds of analysts and thousands of man-hours. By using the SAS analytic tool, you can do the same analysis in a matter of hours with a single analyst. SAS allows you to eliminate unnecessary data and optimize the relevant information. It will enable you to predict an outcome even with missing data, so you can take better decisions.
Alternative SAS Tools
The chart below places SAS beside the two open-source tools most often compared with it.
R: It is open-source software. It is easy to learn R as it is well documented. It offers strong statistical capabilities.
Python is another popular open-source scripting language. Python supports libraries such as NumPy, SciPy, and Matplotlib. You can perform any statistical operation, or you can build any model using these libraries.
SAS: It is the widely used analytical tool in the commercial analytics market, with a plethora of statistical functions and a good GUI.
In this SAS programming tutorial, we will discuss the Statistical Analysis System and how it can be used to solve our problems.
SAS history
- SAS began in the late 1960s as a project at North Carolina State University, where Jim Goodnight worked with Anthony Barr, John Sall and Jane Helwig on a statistical analysis system.
- Initially, it was developed for Agricultural Research.
- The four collaborators incorporated SAS Institute in 1976, and Goodnight has led the company since.
- Later, it expanded to a gamut of tools to include Predictive Analytics, Data Management, BI among others.
- SAS remains widely deployed among the world’s largest corporations for Data analysis and regulated reporting.
Next in this SAS language tutorial, we will learn about features of SAS.
SAS Features
Key features of SAS are:
- Easily access raw data files & data in an external database. Read and write almost any data format!
- Manage data using tools for data entry, editing, retrieval, formatting & conversion
- Analyze data using descriptive statistics, multivariate techniques, forecasting, modeling and linear programming
- Advanced analytics helps you to make changes and improvements in business practices.
- Report formation with perfect graphs
- Operations research and project Management
- Data updating and modification
- Powerful data handling language
- Excellent data cleansing functions
- Interact with multiple host systems
Next in this SAS for beginners tutorial, we will learn about the SAS Product suite.
SAS Product Suite
There are many SAS products available in the market. Following is a list of the more popular ones.
| Name | Description |
|---|---|
| Base SAS | Base SAS software offers hardware agility and integrates into all kind of computing environment. |
| SAS/GRAPH | This tool helps you to represent structured data into graphs. |
| SAS/STAT | This tool helps you to perform different types of regression, statistical analysis variance, regression, and psychometric analysis. |
| SAS/ETS | It is used for forecasting. Helps you to perform the time series analysis. |
| SAS/IML | Interactive Matrix Language is abbreviated to IML. This tool helps you to translate mathematical formulas into an innovative program. |
| SAS EBI | A tool for Business Intelligence Applications |
| SAS Grid Manager | It is a core component which offers data management facility and a programming language for data analysis |
| SAS/OR | Tool for Operation research |
| SAS/QC | Use for Quality control |
| SAS/Enterprise Miner | Data mining |
| SAS/PH | Clinical trial analysis |
| SAS/AF | It offers applications facility |
| Enterprise Guide | It is a GUI based code editor & project manager |
Next in this SAS tutorials guide, we will learn about SAS architecture.
SAS Architecture
The diagram below breaks the deployment into its three tiers.

SAS architecture is divided mainly of three parts:
- Client Tier
- Middle Tier
- Back tier
Client tier
Client tier is where the application is installed on a machine, where the user is sitting. It consists of the components which are used to view the portal and its content. It also includes a standard web browser that is used to interact with the portal over standard HTTP or HTTPS protocol. It also helps you to make the SAS web application firewall friendly.
Middle tier
The middle tier offers a centralized access point for enterprise information. All access to content is processed by components operating in this tier. The separation of the business logic from the display logic helps you to leverage the logic of the middle tier. Moreover, centralized points of access make it easier to enforce security rules, administer the portal and manage code changes.
The middle tier hosts the following functions:
SAS Information Delivery Portal Web Application: It is the collection of JSP, Java servlets, JavaBeans, and other classes and resources. These components help you to access information stored in the enterprise directory to create a customizable interface for the user.
Servlet Engine: The servlet engine is also called a servlet container. It is responsible for managing the SAS Information Delivery Portal Web Application. The servlet engine offers a run time environment. It provides concurrency, deployment, lifecycle management, etc.
Web server: Web server offers service for the servlet engine which can be used to host a website. This should be accessed using the portal.
Back Tier
The back tier is an area where the data and computation servers run which may contain business objects. It is an enterprise directory server. The enterprise directory server maintains metadata about content which is located throughout the enterprise.
How to Download and Install SAS
Note on editions: the walkthrough below documents SAS University Edition, the free desktop and AWS edition that SAS Institute retired in 2021. The free replacement is SAS OnDemand for Academics, which runs SAS Studio in the browser with no VirtualBox image and no AWS instance to manage. SAS also publishes SAS Viya for Learners for cloud-based coursework. Register for one of those, then use the SAS Studio screens shown here, which are near-identical.
Local install on your machine
Step 1) Download SAS from the given link
Go to the SAS free academic software page and click on Get Free Software.
Step 2) Select your Operating System
Select the operating system as per your system, as shown below.
Step 3) Download and install Virtualization Software
SAS University Edition required Virtualization Software such as VirtualBox to be installed before it could be installed. The download screen looked like this:
Follow the steps mentioned onscreen to install SAS. Having VirtualBox and a local install could sometimes be tricky, so the AWS route below was recommended instead.
AWS installation
Note: the SAS University Edition AWS Marketplace listing has been withdrawn, so the URLs quoted in the original steps no longer resolve. The sequence is preserved below because the AWS subscribe-configure-launch flow is unchanged for any SAS Marketplace image you do subscribe to.
You can deploy SAS in AWS. It was eligible for the free tier.
Step 1) Open the SAS University Edition listing on AWS Marketplace. Click “Continue to Subscribe” on the product page shown below.
Step 2) In this next screen, Accept Terms.
Step 3) The subscription is pending and takes up to 10 minutes to approve. You will see the following screen.
Step 4) Refresh the page, and your subscription will be confirmed. Click on Continue to Configuration.
Step 5) Keep settings default and click Continue to Launch.
Step 6) Review the config page. Enter a key-value pair. The rest of the settings should be the default. Click Launch.
Step 7) Go to your AWS Marketplace library and click on View Instances, as shown here.
Step 8) In the popup pictured below:
- Note the instance id. This is your password
- Click Access software
Step 9) In the popup that appears after you click in step 8:
- Enter user credentials. Id: sasdemo password: instance id noted in step 8
- Click Sign in
Step 10) You will see the welcome screen below.
Troubleshooting
If you are not able to connect, open the Security Groups page of the EC2 console for your region and set the inbound and outbound rules to all.
How to Use SAS?
To effectively use SAS software you need to follow four steps, which are: Access Data, Manage Data, Analyze, and Present. The diagram below shows the order.
Access Data:
SAS allows you to access data in any desired format that you want.
You can access data that is stored anywhere, whether it is in a file on your system or data that is stored in another database system. It can be an Oracle file, a SAS database file, a raw database file or a simple XLS/CSV file. It will help you to access this data with ease.
Manage Data:
SAS offers great data management capabilities. You can subset or slice data based on certain conditions, create variables, and clean & validate data. There are other tools which allow you to perform the same task. However, SAS helps you to perform this job with ease.
SAS has well-defined libraries and processes which make the programming process easy. Moreover, creating a variable or subsetting data is a one-step process. This saves you from writing complex algorithms by just a single line of code.
Analyze:
You can do various kinds of analysis using SAS:
- It checks Frequency of Mean calculation
- Regression and Forecasting
- Decision Tree
SAS handles all of these analyses easily. It is a strong tool for accurate forecasting, which is why it sits alongside the other data analytics tools used in enterprise reporting.
Present:
If you visualize data correctly, it is effortless for the audience to relate to it. It is essential that your tool presents the data in a suitable manner. That’s what SAS does for you. It has excellent presentation capabilities.
You can produce:
- List reports
- Summary reports
- Graph reports
- Print reports
SAS Program Example
The next section shows what those stages look like in SAS code.
SAS Program consists of three necessary steps:
- Data Step
- Proc Step
- Output Step
DATA Step
Data step loads the needed data set into SAS memory and finds the correct variables of the data set. It also captures the records. We can use data steps to:
- Enter data into SAS data sets
- Compute Values
- Check or correct data
- Produce new data sets
The syntax for the DATA statement is:
Syntax
DATA data_set_name; #Give a name to the dataset INPUT var1,var2,var3; #Declare variables in the dataset. NEW_VAR; #Define new variables. LABEL; #Give variables a label DATALINES; #Provide data RUN;
Example:
The following example shows how to define a variable, name the data set, create new variables and enter the data. In this example, you can see that string variables have a $ at the end, and numeric values are without it.
INPUT ID $ NAME $ SALARY DEPARTMENT $; comm = SALARY*1.50; LABEL ID = 'Emp_ID' comm = 'COMMISION'; DATALINES; 1 Tom 5000 IT 2 Harry 6000 Operations 3 Michelle 7000 IT 4 Dick 8000 HR 5 John 9000 Finance ; RUN;
Note: To execute a SAS statement you need to specify the RUN command.
PROC Step
It performs specific analysis or functions to produce results and reports.
Syntax
PROC procedure_name options; #The name of the proc. RUN;
Example
The given example uses the MEANS procedure to print the mean values of the numeric variables in the data set.
PROC MEANS; RUN;
The OUTPUT Step
You can display the data from the data set with conditional output statements.
Syntax
PROC PRINT DATA = data_set; OPTIONS; RUN;
Every SAS program must follow all the above mentioned steps to read the input data, analyze the data and give the output of the analysis. The RUN statement at the end of each step finishes the execution of that step.
The complete SAS Program
Below given is the complete code for each of the above steps.
Output:
Running the program produces the printed data set, the descriptive statistics and the final report shown in the three screens below.
Where is SAS used?
Below given are some important SAS applications:
| Industry | Usage |
|---|---|
| Pharmaceutical | Statistical Analysis, Reporting |
| Telecom | ETL, Reporting, Data Mining, Forecasting |
| Financials | ETL, Reporting, Data Mining, Financial research |
| Predictive modeling | DBMarketing, Activity-Based Management |
| Healthcare | ETL, reporting, Data Mining |
SAS Vs. R
The table below sets SAS and R side by side on cost, learning curve and graphics.
| SAS | R |
|---|---|
| SAS is commercial software, so it requires a financial investment. | R is open source software. Hence anyone can use it. |
| SAS is an easiest analytical tool to learn. Even people with limited knowledge of SQL can learn it quickly. | R requires you to write complicated and lengthy codes. |
| SAS is a highly preferred choice by big companies and is quite technically advanced & user-friendly. | R is fast developing software; however, you need to keep upgrading it. |
| SAS has good graphical support but does not offer any customization. | Graphical support of R tool is very poor. |
Advantages of SAS
- SAS has an easy syntax which can be learned without any type of programming knowledge
- Ability to handle a large database with ease
- SAS is a very comprehensible language which can easily be debugged
- Its “log” window clearly states the error, which helps you to debug your code easily
- SAS helps you thoroughly test and analyze the algorithm
- SAS is completely secured, so you cannot extract it without a license in the office
- Makes statistical computing easier for non-programming users
- Handles large size databases effectively.
Disadvantages of SAS
- Cost is high, because an individual or organization cannot use all its applications without a proper license
- SAS is not open source, so algorithms used in SAS are not available for common use
- Text mining is a very troublesome and difficult process in SAS.
- Community answers and third-party packages are fewer than for open-source stacks used in data science and machine learning work.


















