When we work in SAS, we want to keep track of the submitted code and output. Therefore, it is crucial to know your log and results viewer well. Because they can get messy. Your log can be filled with millions of lines. Also, your results viewer can contain much information you do not need. Therefore, it is convenient clean up the mess so you can stay focused on what is important. Here, I will show how to clear the log and results viewer using simple SAS code.
Firstly, let us look at how to clear the SAS log with simple code. I use the DM Statement with LOG ‘CLEAR’ as arguments to clear everything in the current log. Actually, I do the same thing with the output viewer, though I rarely use it. You can achieve the same result by going to Edit –> Clear All in your editor while having the log active. I like the code method better though.
/* Clean log and output */ dm log "clear"; dm output "clear";
Clear Results Viewer
You can also clear the HTML results viewer using code in SAS, though the concept is a bit different. Here, we do not use the DM Statement. Rather, we use the ODS Statement to simply close the HTML window and immediately open a new one. The HTML Results Viewer is the standard destination for ODS output in SAS, though this is only the case from SAS 9.3 and forward. Before that the Listings Destination was standard.
ods html close;
Another trick, I often use when I work in SAS is to force the HTML Results Viewer to show only the results from the latest submitted code or procedure. This can be achieved with the ODS HTML NEWFILE=PROC Statement. This tells SAS that the HTML destination should only contain output from the latest submitted procedure. This is very useful when you run some procedure multiple times and make small corrections to it. In that case, it can be difficult to navigate to the exact place in the HTML Window of your interest, because a lot of the results will look the same. The small program below does exactly that.
/* Results Viewer show only last procedure */ ods preferences; ods html close; ods html newfile=proc;
It is often very convenient to clear out the things you do not need, whether it is in your log, results viewer or some third place. I use these tricks very often. That is why, I have added abbreviations in my editor so that I do not have to memorize the code, only what the abbreviation does. The process of adding an abbreviation in your editor is shown in the blog post Save Typing And Add Abbreviation In SAS. You can see many other tricks of clearing logs, results and whole libraries in the great article Taking Out the Garbage by Adam LaManna and Howard M. Proskin.
You can download the entire code from this post here.