The SAS structure and debugging your programs

Last changed: 10 February 2021

When you open SAS you will see 3 windows:

- The Editor, where you will write your programs

- the Log window, that will indicate if there are errors in the program and

- the Output window, which will show the output

In later versions you can also have a Results viewer, which is used instead of the Output window and gives output as html files. Depending on what you prefer the Results viewer can have a number of disadvantages, for example, it can not easily be cleared of all text. Find here how to change from the Results viewer to the regular Output window.

To the left you will also find the Explorer or the Results Window, there you will see all the programs you have run during one session.

Writing and running a program:

SAS programs are written in the SAS editor. The program is run by marking the code (right mouse-click, mark all code) and clicking submit or pressing F8 (you can run the entire program by pressing F8 – without marking – but usually you will do programming in small parts and then you can mark only the part you want to run). Whenever some program code is submitted you check if everything is ok by studying the Log Window – there you will find errors, warnings and notes.

If the program is correct and you have run a procedure step (PROC…) you will get the output in the Output window. If you run a data step (DATA …) there will be no output.

If you write code it is useful to comment on the different parts of the program. To insert a comment, write * in the beginning of the line. If you want to write a long comment or a comment containing ‘;’write instead /* to start the comment and */ to end the comment.

Try it:

data first;
input length;
cards;
3
5
7
8
;run;

Press F8. You will not get an output but the Log Window should show you that you have just created a new data set with 4 observations. The data set is called first and the variable in the dataset is called length, both are chosen by the user. The bold text is SAS syntax and need to be given in this order.

Check out why the data set in SAS is called work.first or move on to the next chapter where you learn more about reading and writing data in SAS.

 

 


Contact