
In this blog, I will show you some important ideas about SAS programming. But before we begin, it's a good idea to learn what SAS is. You can read my earlier blog called "SAS Tutorial" to understand what SAS does, how it is used, and how to install SAS University Edition.
🌟 SAS Programming Basics for Beginners
🖥 SAS Windows – What They Do
-
Log Window: This window shows what happens when your code runs.
-
Output Window: This window shows the final result of your code.
-
Result Window: Think of this as a list. It shows all the outputs created during your current session.
📁 SAS Data Sets
In SAS, data sets are like tables.
-
Rows are called observations
-
Columns are called variables
These data sets are also called data files.
🔠 SAS Variables
SAS has two kinds of variables:
-
Numeric Variables: These are numbers. You can use them in math calculations.
-
Character Variables: These are words or text (like names).
📚 SAS Libraries
A SAS Library is a place (or folder) on your computer where SAS keeps your files.
-
Temporary Library: The data is saved only while you’re using SAS. Once you close it, the data is gone..
-
User-Defined Library: You can make your own library using a special keyword called LIBNAME.
🧱 SAS Code Structure – How It Works
SAS code has two main parts:
-
DATA Step: This part creates the data set.
-
PROC Step: This part processes (or works with) the data.
✅ Rules for writing SAS code:
-
Most programs in SAS begin with a DATA or PROC step.
-
Each line of code has to end with a semicolon (;)
-
A SAS program ends with RUN or QUIT.
✍️ Let’s Write Another SAS Code!
sas
Copy Edit
DATA Student_ Grades;
input Student _ID Student_ Name$ Subject$;
data lines;
201 Anya Math
202 Rohan Science
203 Diya English
204 Kabir History
205 Neha Math
;
Run;
🔍 What Does This Code Do?
-
DATA Student_Grades: This makes a new data set called Student_Grades.
-
input Student_ID Student_Name$ Subject$: Here, we tell SAS what kind of data we are using.
-
Student_ID is a number.
-
Student_Name$ and Subject$ are words (text), so they have a $.
-
datalines: This is where we type in the actual data. Each line gives the student’s ID, name, and subject.
📘 Informats and Formats in SAS
To be good at SAS programming, you need to understand Informats and Formats.
Earlier, we learned that SAS uses two main types of variables:
-
Numeric (numbers)
-
Character (words or text)
🕓 What is an Informat?
Informats help SAS read data from outside files, like text files. They tell SAS how to read and understand the data when bringing it in.
There are 3 main types of Informats in SAS:
-
Character Informat – used for words or text.
Example: $INFORMATw. -
Numeric Informat – used for numbers.
Example: INFORMATw.d -
Date/Time Informat – used for dates and times.
Example: INFORMATw.
✍️ SAS Code Example with Date Informat
sas
CopyEdit
DATA Student_Info;
input Student_ID Student_Name$ Subject$ Admission_Date;
INFORMAT Admission_Date ddmmyy10.;
datalines;
201 Anya Math 12/06/2020
202 Rohan Science 05/07/2019
203 Diya English 20/03/2021
204 Kabir History 15/01/2018
205 Neha Math 30/11/2022
;
Run;
🔍 What Does This Code Do?
-
DATA Student_Info: This creates a new data set called Student_Info.
-
input Student_ID Student_Name$ Subject$ Admission_Date: It reads 4 values: an ID, a name (text), a subject (text), and the date the student was admitted.
-
INFORMAT Admission_Date ddmmyy10.: This tells SAS how to read the date for Admission_Date in the day-month-year format.
-
dmmyy10. means the date is in day/month/year format and uses 10 spaces (like 12/06/2020).
-
datalines: This is where the data is entered.
-
Run: This tells SAS to run the data step.
-
PROC PRINT DATA=Student_Info: This prints the data set so you can see the result in the Output Window.
SAS Loops
Sometimes, when we write SAS programs, we need to run the same group of steps many times. We use a loop to repeat code so we don’t have to write the same thing over and over. In SAS, we use the Do statement to make a loop that runs again and again.This is called a Do Loop. It helps us repeat actions easily without typing everything over and over.
📊 Basic Statistics in SAS
➕ What is PROC MEANS?
In SAS, we can use something called PROC MEANS to do math with numbers. It helps us find the average (also called the mean) and something called standard deviation.
🧮 What is Arithmetic Mean?
The mean is the average you get when you add up all the numbers and divide by how many there are.
1. Add up all the numbers
2. Divide the total by how many numbers you have
This tells you the middle value of the data. That’s why it’s also called a measure of central tendency—it shows where the center of your data is.
📏 What is Standard Deviation?
Standard deviation is a way to see how spread out the numbers are in a group of data.
-
A large standard deviation means the numbers are not close together and are far from the average.
-
If the standard deviation is high, it means the numbers are spread out and far from the average.
🧮 How to Find Standard Deviation in SAS
In SAS, you can find the standard deviation in two main ways.
-
PROC MEANS
-
PROC SURVEYMEANS
If you use PROC MEANS, just add the STD option in your code.
✍️ Example: Using PROC SURVEYMEANS in SAS
sas
CopyEdit
DATA Fruits;
input Fruit_Type$ Weight;
datalines;
Apple 120
Apple 130
Banana 100
Banana 110
Orange 140
Orange 135
;
Run;
🔍 What This Code Does
-
DATA Fruits: This creates a data set with fruit types and their weights.
-
PROC SURVEYMEANS DATA=Fruits STD: This tells SAS to find the standard deviation (how spread out the numbers are) for each type of fruit.
-
Class Fruit_Type: This groups the data by fruit type (Apple, Banana, Orange).
-
Var Weight: This tells SAS to measure the standard deviation of the weight.
-
ods output statistics=Fruit_Stats: This saves the results in a new data set called Fruit_Stats.
-
PROC PRINT: Prints the results.
How to obtain SAS Programming certification?
We are an Education Technology company providing certification training courses to accelerate careers of working professionals worldwide. We impart training through instructor-led classroom workshops, instructor-led live virtual training sessions, and self-paced e-learning courses.
We have successfully conducted training sessions in 108 countries across the globe and enabled thousands of working professionals to enhance the scope of their careers.
Our enterprise training portfolio includes in-demand and globally recognized certification training courses in Project Management, Quality Management, Business Analysis, IT Service Management, Agile and Scrum, Cyber Security, Data Science, and Emerging Technologies. Download our Enterprise Training Catalog from https://www.icertglobal.com/corporate-training-for-enterprises.php and https://www.icertglobal.com/index.php
Popular Courses include:
-
Project Management: PMP, CAPM ,PMI RMP
-
Quality Management: Six Sigma Black Belt ,Lean Six Sigma Green Belt, Lean Management, Minitab,CMMI
-
Business Analysis: CBAP, CCBA, ECBA
-
Agile Training: PMI-ACP , CSM , CSPO
-
Scrum Training: CSM
-
DevOps
-
Program Management: PgMP
-
Cloud Technology: Exin Cloud Computing
-
Citrix Client Adminisration: Citrix Cloud Administration
The 10 top-paying certifications to target in 2025 are:
Conclusion:
Now you know the basics of SAS programming! You learned how to work with data sets,write SAS code, and use important steps like DATA and PROC. You also found out how to use loops, informats, and keywords like PROC MEANS and PROC SURVEYMEANS to do math with your data.We even looked at how to find the average (mean) and how to check if numbers are spread out (standard deviation). You also saw how to group data, add dates, and print results in a simple way
Contact Us For More Information:
Visit :www.icertglobal.com Email : 
Comments (0)
Write a Comment
Your email address will not be published. Required fields are marked (*)