The purpose of this post is to help you understand the fundamentals of SAS programming environment and language. It is intended to give first time users an idea about the SAS software and how to access it and get you up and ready with SAS programming. At the end of this tutorial, you would be acquainted with SAS basic syntax rules, how to enter data into SAS, variable types and how to run a program in SAS. If you really want to make your career in analytics, you should focus on learning SAS programming as SAS is a world leader in softwares for advanced analytics. To see the real potential of SAS programming, login to any job portal and search for jobs required skill set of SAS. You would find a large number of jobs waiting for you if you know SAS.
Free Download and Install SAS Software
Fundamentals of SAS Programming
Let's look at a simple SAS program :
Submit the program
SAS Log Window
It is where error messages and executed SAS commands are printed.
SAS Output Window
Basic SAS Program Rules
Read and Modify above SAS Data Set
SAS stands for Statistical Analysis System.
What SAS can do?
It can perform the following tasks:
- It allows you to enter, retrieve and manage your data easily
- It can read data from various external sources (Excel, CSV, Text files, Databases, Webpage etc)
- You can explore and manipulate data in SAS.
- It can analyze your data statistically and mathematically. Includes various statistical techniques.
- It can generate beautiful graphs and tables.
- You can run SQL queries on SAS datasets.
- You can automate repetitive tasks with SAS Macros.
- It can develop entirely new software applications.
Check out this link - Free Access to SAS Software.
SAS has three windows :
- Editor Window: where you type programs for analyzing data
- Log Window: where error messages and executed SAS commands are printed
- Output Window: where the result of SAS programs are printed. There is one more window linked to this window - Result Window. In result window, you can see each section of your output.
![]() |
Getting Started in SAS |
Let's look at a simple SAS program :
![]() |
A Simple SAS Program |
Submit the program
To submit the program, press F3 or F8 shortcut key. Alternatively, you can click on click on the icon of “the little guy running” at the top of the SAS tool bar.
SAS Log Window
It is where error messages and executed SAS commands are printed.
![]() |
SAS Log Window |
SAS Output Window
![]() |
SAS Output Window |
Where SAS data sets are stored?
SAS files are stored in a SAS library. A SAS library is simply a collection of SAS files (data sets) that are stored in a folder. SAS files are stored either temporarily or permanently. By default, it is stored in a temporary library called Work.
How to create a SAS library
1. Temporary : When you don't specify a library name at all, then the file is stored in a temporary SAS library called Work. When you close out the SAS session in which you created the SAS file, the temporary library and all of its files are removed from your computer's memory.
data example;
In this case, example is a data set that is stored in work library.
Note : You can specify the library name Work followed by dot (.) and then data set name.
data work.example;
2. Permanent : If you use a library name other than the default library name 'Work' when creating a SAS file, then the file is stored permanently until you delete it. That is, you can use permanent SAS libraries and their contents in subsequent SAS sessions.
You can specify the library name followed by dot (.) sign and then data set name.
data mydata.example;In this case, example1 is a data set that is stored in mydata library.
Basic SAS Program Rules
I. Rules for SAS statements
II. Rules for SAS names
III. Rules for SAS variables
DATA Steps
- All SAS statements (except those containing data) must end with a semicolon (;).
Example : "DATA example1;" is an example of a SAS statement.
- Any number of SAS statements can appear on a single line provided they are separated by a semicolon.
Example : "DATA example1; Input Name $ ID;" is an example of a SAS statement.
- SAS statements typically begin with a SAS keyword. (DATA, PROC)
- SAS statements are not case sensitive, that is, they can be entered in lowercase, uppercase, or a mixture of the two.
Example : SAS keywords (DATA, PROC) are not case sensitive
- A delimited comment begins with a forward slash-asterisk (/*) and ends with an asterisk-forward slash (*/). All text within the delimiters is ignored by SAS.
II. Rules for SAS names
- All names must contain between 1 and 32 characters.
- The first character appearing in a name must be a letter (A, B, ...Z, a, b, ... z) or an underscore (_). Subsequent characters must be letters, numbers, or underscores. That is, no other characters, such as $, %, or & are permitted. Blanks also cannot appear in SAS names.
- SAS names are not case sensitive, that is, they can be entered in lowercase, uppercase, or a mixture of the two. (SAS is only case sensitive within quotation marks.)
III. Rules for SAS variables
If the variable in the INPUT statement is followed by a dollar sign ($), SAS assumes this is a character variable. Otherwise, the variable is considered as a numeric variable.
Difference between 'PROC' steps and 'DATA' steps
DATA Steps
Any portion of a SAS program that begins with a DATA statement and ends with a RUN statement is called a DATA Step.
DATA steps are used to manage data. In detail, DATA steps are used to read raw or external data into a SAS data set, to modify data values, and to subset or merge data sets.
PROC Steps (Procedures)
Any portion of a SAS program that begins with a PROC statement and ends with a RUN statement is called a PROC Step or Procedures.Example SAS Code for Practice
PROC steps are in-built programs that allow us to analyze the data contained in a SAS data set. PROC steps are used to calculate descriptive statistics, to generate summary reports, and to create summary graphs and charts.
/*A Simple SAS Program*/The above program creates a dataset named 'temp' which is stored in WORK library. In the dataset, there are 2 variables/columns - NAME and ID which contains 4 observations/rows. The command 'PROC PRINT' tells SAS to print the dataset in Output Window.
data temp;
input name $ ID;
cards;
Sam 12
Sandy 13
Reno 11
Farhan 10
;
proc print;
run;
Read and Modify above SAS Data Set
data out;
set temp;
if ID > 10;
run;
The SET statement allows you to read values from a SAS data set (temp). The SAS Statement 'IF ID > 10' tells SAS to read only those ID values that are greater than 10. Later SAS paste these values into a new data set (OUT) without overwriting existing data set (temp)
Step by Step Learning : 100 Free SAS Tutorials
Analytics Companies using SAS in India
Step by Step Learning : 100 Free SAS Tutorials
Analytics Companies using SAS in India
Hi.. I was seraching for a free SAS book online and found this website. its excellent.. keep u the great work
ReplyDeletethanks
It is great site for SAS Learners. Appreciate your great work.
ReplyDeletethanks
awesome site to learn sas, nd thanx a lot ..
ReplyDeleteThis is the wonderful job you're doing. Thanks.
ReplyDeleteAwesome site to learn SAS and data analysis.
ReplyDeleteExcellent work! Just started as a student (programmer) assistent, and is learning SAS. This site is helping alot!
ReplyDeleteGreat work..Really very useful for people who wants to start SAS from ground level.Everyone can easily understand the subject.
ReplyDeleteExcellent work sir.... Thank you very much
ReplyDeleteexcellent website to revisit the concepts for SAS and sql. Keep up the good work !!!
ReplyDeleteThank you for your appreciation!
DeleteU have made learning so easy with Examples. Thanks a Ton!..keep up the good work to help others!.. :)
ReplyDeleteGlad you found it useful!
DeleteBeginners delight! Keep posting...
ReplyDeleteexcellent work sir thanks...........
ReplyDeleteSuch a great stuff from such a great person!! Thank you :)
ReplyDeleteThank you for your lovely words!
DeleteTHANK YOU VERY MUCH I GOT UR SITE INFO FROM AON EMPLOYEE
ReplyDeleteThank you for stopping by my blog. Say 'Thanks' to the Aon Employee who spreaded the word about 'ListenData' :D
Deleteno more words really very nice..why don't you take a classes?
ReplyDeleteThank you :)
Thank you for stopping by my blog. I'll think about taking classes :)
DeleteThank you sir.. :)
ReplyDeleteThx for sharing it's very easy to use
ReplyDeleteHi, I am a new learner of SAS. I had lot of apprehension about SAS because I thought programming is not my cup of tea. I found this website and really enjoying learning SAS. Thanks a ton for sharing your knowledge in such a clear way. Keep up good work. look forward to many more tutorial sessions...
ReplyDeleteThank you very much for taking time out of your busy schedule to give your feedback. Cheers!
DeleteHi, Deepanshu, thanks for the outstanding explanation. Iam a beginner in SAS CLINICAL. What's your suggestions for a beginner like me with out any prior programming language. Your kind suggestions will be appreciated. Thanks. Azhar.
Deleteexcellent website for beginners . Thank you so much for such an amazing content.
ReplyDeleteguys sasstudio is not accepting input from my keyborad please suggest what should i do
ReplyDeleteGREAT WORK, THANK YOU SO MUCH :)
ReplyDeleteGreat work Sir.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteVery useful. thank you
ReplyDeleteIt's an wonderful platform for beginners especially without programming language
ReplyDeleteThank you very much!! This is really helpful.
ReplyDeleteReally good . and thank you so much for this fantastic content.
ReplyDeleteSo easy to learn.the way you described is great.
ReplyDeleteExcellent work done by developers....very easy way to learn SAS through this content.....fantastic content and easy to understand
ReplyDeleteBest place to refresh SAS. Great job. Awesome, I'm liking it a lot.
ReplyDelete