How to clear the output window in SAS 9.3


One of the highly visible changes in SAS 9.3 is the fact that the old LISTING destination is no longer the default destination for ODS output. Instead, the HTML destination is the default.

One positive consequence of this is that ODS graphics and tables are interlaced in the output. Another is that complicated tables are easier to read because SAS can use styles (colors, fonts, and cell shading) to make tables more readable. For example, the row and column headings of a table might be a different color than the cells of the table.

However, if you are like me, you occasionally like to clear the output window so that it doesn't get too crowded. In SAS 9.2, clearing the Output Window (by which I mean the LISTING destination) in the SAS Windowing Environment was easy: select Edit > Clear All or select the Output Window and click the New icon (or File > New).

I assumed that I could clear the HTML Results Viewer in SAS 9.3 the same way, but as the following image shows, the Edit > Clear All menu item is disabled!

No worries, though. You can clear the Results Viewer programmatically by submitting the following statements:

ods html close; /* close previous */
ods html; /* open new */

The Results Viewer will not immediately look empty, but the next time that you generate output you will see that the Results Viewer no longer includes the older content.

There is a SAS Usage Note that describes other ways to clear the contents of the Results Viewer. Thanks to the fine folks on the SAS-L Mailing List for asking this question and for linking to the SAS Knowledge Base article.

Update, Fall 2012: This problem is FIXED at SAS 9.3M2 (the 12.1 release for SAS/STAT, SAS/ETS, SAS/IML, etc.). At 9.3M3 you can just choose Edit > Clear All from the main menu and the HTML output is cleared. *Phew!*


About Author

Rick Wicklin

Distinguished Researcher in Computational Statistics

Rick Wicklin, PhD, is a distinguished researcher in computational statistics at SAS and is a principal developer of SAS/IML software. His areas of expertise include computational statistics, simulation, statistical graphics, and modern methods in statistical data analysis. Rick is author of the books Statistical Programming with SAS/IML Software and Simulating Data with SAS.


  1. This works OK, better than the Usage note you linked to. But neither is really adequate-- your approach requires a lot of typing, and the usage not makes a lot of files. What's really needed is a button, or a worst a function-key mappable command.

  2. It would be fine to tie your approach to a function key-- is there a way to use SAS statements in the definitions in the KEYS window? This used to be possible with %keydef, but its not obvious that this can be done anymore.

    The macro

    %macro clearoutput;
    ods html close;
    ods html;
    %mend clearoutput;

    works fine. I can just store it permanently, but I'd still have to use a lot of keystrokes. I really want to associate it with a function key or a button. Do you know of a way to do that?

  3. Got it-- the gsubmit command.

    If you open the keys window (or customize a tool) to read

    gsubmit "ods html close; ods html;"

    then the key (or toolbar button) will shut the (current) html output file and open a new one. It doesn't clear the results viewer, or, I think, delete the old file. Which could prove useful, occasionally.

  4. Pingback: Readers’ choice 2011: The DO Loop’s 10 most popular posts - The DO Loop

  5. Ken, many thanks! I set up the F12 key and now press it whenever I need a clean output window before a new run. Wonderful solution to a vexing problem. You might remind folks to hit "Save" after doing the "gsubmit..." Your newest fan, Roger

  6. Kristen Fessele on

    Yes, the step by step instructions were easy to follow, and worked perfectly. This issue was really bugging me, so I thank you very much!

  7. Edward Ballard on

    I don't have 9.3 but up through 9.2.3 have used odsresults; select all;clear; assigned to a function key for similar purpose. Does this still work in 9.3?

      • Tor Neilands on

        Does anyone know if there is a way to clear the results "tree"/TOC via issuing a command or set of commands as code written in the program editor window? (much as one can do to clear the output with Rick's suggested ods html close; ods html; sequence). Thanks.

        • Chris Hemedinger
          Chris Hemedinger on

          Tor, try this combination:


          ODSRES puts focus on the ODS Results window, and CLEAR...well...clears it.

  8. Merdi Rafiei on

    I tried Ken's step by step instructions on how to clear the Results Viewer window, but it doesn't work for me! When I click on the icon I've created for this task nothing happens... I'm running 64-bit SAS 9.3 on Windows 7 Professional (if it makes any difference). Any and all help will be greatly appreciated.

    • Chris Hemedinger
      Chris Hemedinger on

      The GSUBMIT command puts statements from the Windows clipboard, or other commands that you specify, into the "submit buffer" stream for the currently active session. It's possible that the shortcut won't work if the active window isn't one that can process the command, or the active session is already busy processing something else. Also, the command has to be on the HTML results window, not the editor window. If you don't see the statements reflected in the log, it didn't work.

      In the notes for GSUBMIT, there is this:

      SAS statements in the Windows clipboard will not be submitted using the GSUBMIT command if a procedure that you submitted using the Enhanced Editor is still running. You can copy the SAS statements to a new Enhanced Editor window and then submit them.

      I was able to get it working with SAS 9.3 64-bit on Windows.

  9. I just copied and pasted the codes that Rick Wicklin gave above into my SAS file at an early point and it worked fine. Copy and paste is good and I keep things simple by renaming and modifying programs that work. That way, the codes will be there.

    Thanks Rick.

    Nonetheless, as simple as I am, I've been able to set a single keystroke to clear all the other windows and it seems this should be a nobrainer for the gurus at SAS.

  10. Ok, nice! I did it but I modified it a bit. I defined a function key, but instead of putting it it:

    gsubmit "ods html close; ods html;"

    I've put it it:

    gsubmit "ods html close; ods html;"; submit

    So the window is cleared and the code is launched automatically. It seems to work, but every second time (I have to kit the key twice to have this running one time). The other problem that I have is that - if I run codes that generate graphs - my working directory gets full of png files! How can this be solved?

    Thanks for any help on this!


    • Rick Wicklin

      Well, I suppose that you could delete the PNG files yourself by hooking some SAS code into the function key (or creating a new function key), but if it were me, I wouldn't worry about it unless it is causing problems. The WORK directory will get cleaned up when you exit SAS.

      • Thanks!

        1) No the directory is not cleaned up when I exit SAS! These file are annoying (I got hundreds of them rapidly).

        2) You are not answering my first point: Why do I have to launch thing always twice?

        Thanks in all cases for your time!

        Cheers, Eric.

        • Rick Wicklin

          1) If the WORK directory is not cleaned up upon exit, I do not know why. You can call SAS Technical Support. They might have seen this problem before and can suggest a solution.
          2) I do not know why you have to hit the function key twice. I and others have offered several options that work.

  11. Thanks for the tip! I like to clear output at the top of every script. Here's how I'm making that happen in 9.3, thanks to folks here.

    ods html close;
    ods html;
    dm 'odsres; select all;clear;';

  12. I created a new key as described above which worked nicely but I also found that while in the ODS output window I could just use CTRL+E to clear and close that window in one step.

    • Chandra,

      Thanks for the short cut, that you have given, it is working fine for me. but i have a question.
      Did you create that shortcut? or is it predefined in SAS?
      if you have created it, could you please let me know how to create?

      Thank you for you help

  13. Hi Rick, is there any shortcut key in SAS 9.3 for show "results viewer"?
    In SAS 9.2 I used F5 F6 F7 to siwtch between enhanced editor/ log/ output, but now "results viewer" is the default output destination, I need a shortcut key to show it.

    thanks a lot~~

Leave A Reply

Back to Top