Getting Started with SAS

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.
SAS stands for Statistical Analysis System.

What SAS can do?

It can perform the following tasks:
  1. It allows you to enter, retrieve and manage your data easily
  2. It can read data from various external sources (Excel, CSV, Text files, Databases, Webpage etc)
  3. You can explore and manipulate data in SAS.
  4. It can analyze your data statistically and mathematically. Includes various statistical techniques.
  5. It can generate beautiful graphs and tables.
  6. You can run SQL queries on SAS datasets.
  7. You can automate repetitive tasks with SAS Macros.
  8. It can develop entirely new software applications.

Free Download and Install SAS Software
Check out this link - Free Access to SAS Software.

Fundamentals of SAS Programming

SAS has three windows :
  1. Editor Window: where you type programs for analyzing data
  2. Log Window: where error messages and executed SAS commands are printed
  3. 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.

SAS Libraries

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

  • 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.

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.
Example SAS Code for Practice

/*A Simple SAS Program*/
data temp;
input name $ ID;
Sam 12
Sandy 13
Reno 11
Farhan 10
proc print;
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.

Read and Modify above SAS Data Set
data out;
set temp;
if ID > 10;
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
Spread the Word!
Related Posts
About Author:

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 10 years of experience in data science. During his tenure, he has worked with global clients in various domains like Banking, Insurance, Private Equity, Telecom and Human Resource.

37 Responses to "Getting Started with SAS"
  1. Hi.. I was seraching for a free SAS book online and found this website. its excellent.. keep u the great work

  2. It is great site for SAS Learners. Appreciate your great work.

  3. awesome site to learn sas, nd thanx a lot ..

  4. This is the wonderful job you're doing. Thanks.

  5. Awesome site to learn SAS and data analysis.

  6. Excellent work! Just started as a student (programmer) assistent, and is learning SAS. This site is helping alot!

  7. Great work..Really very useful for people who wants to start SAS from ground level.Everyone can easily understand the subject.

  8. Excellent work sir.... Thank you very much

  9. excellent website to revisit the concepts for SAS and sql. Keep up the good work !!!

  10. U have made learning so easy with Examples. Thanks a Ton!..keep up the good work to help others!.. :)

  11. Beginners delight! Keep posting...

  12. excellent work sir thanks...........

  13. Such a great stuff from such a great person!! Thank you :)


    1. Thank you for stopping by my blog. Say 'Thanks' to the Aon Employee who spreaded the word about 'ListenData' :D

  15. no more words really very nice..why don't you take a classes?
    Thank you :)

    1. Thank you for stopping by my blog. I'll think about taking classes :)

  16. Thx for sharing it's very easy to use

  17. Hi, 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...

    1. Thank you very much for taking time out of your busy schedule to give your feedback. Cheers!

    2. Hi, 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.

  18. excellent website for beginners . Thank you so much for such an amazing content.

  19. guys sasstudio is not accepting input from my keyborad please suggest what should i do


  21. Great work Sir.

  22. This comment has been removed by a blog administrator.

  23. It's an wonderful platform for beginners especially without programming language

  24. Thank you very much!! This is really helpful.

  25. Really good . and thank you so much for this fantastic content.

  26. So easy to learn.the way you described is great.

  27. Excellent work done by developers....very easy way to learn SAS through this content.....fantastic content and easy to understand

  28. Best place to refresh SAS. Great job. Awesome, I'm liking it a lot.


Next → ← Prev

Looks like you are using an ad blocker!

To continue reading you need to turnoff adblocker and refresh the page. We rely on advertising to help fund our site. Please whitelist us if you enjoy our content.