First Sample SAS Program

Sample SAS program : SAS program is a sequence of SAS statements in executed order. SAS program will have 2 steps, Data step and Proc Step.

Data Step : Data steps are typically used to retrieve the data and create SAS data sets.

Proc Step : Proc steps are typically used to process SAS data sets to generate reports and graphs, edit data and sort data.

In this SAS tutorial, we shall learn how to write our first SAS sample program in SAS studio with an example. As a first step, let us make sure that SAS studio is ready and running. If not learn how to download & Install SAS university Edition in your local pc.

Writing our first Sample SAS program

  • In our first step, open Oracle VM Virtualbox manager and and click on start button.
  • We can connect to SAS University edition software by entering the address http://localhost:10080 in web browser.
  • In browser a tab will be opened, where user must click on Start SAS Studio link as shown below.

Now navigate to New options and select New SAS program, which is available on the right side of the menu bar.

Now new program editor will be opened, displaying with different tools that are required for SAS programming.

In this sample SAS program, we are going to enter data in SAS program itself using DATALINES statement. This DATALINES statement must only used, whenever the data doesn’t contain semicolon (;).

Writing our first sample SAS program in Editor window

In this SAS example, we shall use Data step and Proc step. The below example shows a simple program of naming a data set, defining the variables, creating new variables and entering the data. The string variables are mentioned with $ at the end.

Data sampleSASprogram;
Infile Datalines;
Input id name$ sex$ age sal;
Datalines;
001 Rahul M 27 30000
002 Vijay M 29 45000
003 Anvitha F 30 60000
004 Neha F 25 20000
005 John M 44 56000
;
Run;

We can read the data from existing SAS Data sets which are located in personal / Server computers.

Example:- 

Data ds2;
Set ds;
Run;

Data work.ds;
Set sashelp.class;
Run;

Editor Window

In SAS, editor window is used to write program, modify and submit the program for execution. The default editor is the enhanced editor. The enhanced editor is syntax sensitive and color codes your program making it easier to read them and find mistakes

Log Window

Log window contains information of program which submitted in Editor window. Generally we can get here notes, warnings and errors

Result Window

The result window in SAS is like a table of contents for your output window. The results tree lists each part of your result in an outline form.

Output Window

If your program generates any printable results, then it will appear in the output window.