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!*

tags: 9.3, Getting Started, SAS Programming

30 Comments

  1. Posted August 29, 2011 at 9:57 am | Permalink

    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. Posted August 30, 2011 at 6:07 pm | Permalink

    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. Posted August 31, 2011 at 9:03 pm | Permalink

    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. Posted August 31, 2011 at 9:37 pm | Permalink
    • Henry Wang
      Posted February 16, 2012 at 10:22 am | Permalink

      appreciate the tip. very helpful!

    • Eric Leifer
      Posted April 3, 2012 at 7:18 pm | Permalink

      Thanks, Ken, for your very helpful step-by-step instructions. I did find that I had to click my new "clear results" icon each time before running a new script, but this figures to reason since some times I would want to keep the older results. Thanks again.

    • Marlene Dorenkamp
      Posted January 27, 2014 at 12:15 pm | Permalink

      I used the step by step instructions. It didn't work, so I deleted the ods statement from F12. Now I can't even see my results. I get the warning "No output destination active". What did I do wrong?

      • Posted January 27, 2014 at 12:57 pm | Permalink

        If you followed Ken's instructions, contact him. Or contact SAS technical support to get an official solution.

  5. Angela Sauaia
    Posted September 11, 2011 at 6:50 pm | Permalink

    Thanks, Ken, your step by step instructions worked like a charm! Thanks for sharing! Angela

  6. Posted September 22, 2011 at 2:17 pm | Permalink

    Thanks, Angela-- nice to hear someone saw this! If you follow the commands I mentioned with ; wpgm, you'll also go back to the most recent program window.

  7. Roger Hayes
    Posted January 17, 2012 at 11:21 pm | Permalink

    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

  8. Kristen Fessele
    Posted February 6, 2012 at 10:12 am | Permalink

    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!

  9. Edward Ballard
    Posted February 15, 2012 at 7:08 pm | Permalink

    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?

    • Posted February 16, 2012 at 5:51 am | Permalink

      It still "works" in that it clears the ODS results viewer, which is like a table of contents. However, it does not close the default html destination.

      • Tor Neilands
        Posted July 31, 2012 at 1:35 pm | Permalink

        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
          Posted August 3, 2012 at 8:42 am | Permalink

          Tor, try this combination:

          odsres;clear;

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

  10. Merdi Rafiei
    Posted June 9, 2012 at 11:10 pm | Permalink

    Hi,
    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
      Posted June 12, 2012 at 8:54 am | Permalink

      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.

  11. Emad
    Posted November 5, 2012 at 4:39 am | Permalink

    Thank you

  12. Leonard
    Posted November 20, 2012 at 5:02 pm | Permalink

    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.

    • Posted November 20, 2012 at 6:06 pm | Permalink

      You'll be happy to know that this problem was fixed in the 9.3M2 version of SAS. In later releases, click in the output window to activate it, and select Edit-->Clear All.

  13. Eric
    Posted December 21, 2012 at 7:43 am | Permalink

    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!

    Eric.

    • Posted December 21, 2012 at 7:48 am | Permalink

      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.

      • Eric
        Posted December 21, 2012 at 8:08 am | Permalink

        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.

        • Posted December 21, 2012 at 8:27 am | Permalink

          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.

  14. Josh Powell
    Posted January 31, 2013 at 2:34 pm | Permalink

    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;';

  15. suresh
    Posted February 12, 2013 at 12:43 pm | Permalink

    how can we print only the report procedure output on output window while run the entaire program?

  16. Chandra
    Posted July 29, 2013 at 11:20 am | Permalink

    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.

    • Subbarao
      Posted November 19, 2013 at 1:47 am | Permalink

      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

One Trackback

  1. [...] How to clear the output window in SAS 9.3: When you run SAS 9.3 in the windowing environment, HTML is the default output destination. This article describes how to clear the tables and graphics in the HTML destination. [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <p> <pre lang="" line="" escaped=""> <q cite=""> <strike> <strong>