The SAS Output Delivery System and reporting techniques

SAS 9.3-Resetting to initial "ODS state"

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

SAS 9.3-Resetting to initial "ODS state"

I imagine not many of you have 9.3 installed yet ... but as you may (or may not) be aware SAS 9.3 (in Windows at least) comes shipped so that the default output is to the HTML ODS destination and LISTING ODS destination is NOT active.

Anyway, what I'm wondering about is there a way via code to determine the initial state of active ODS destinations when a program is launched --- reason I ask is the program I'm working on right now activates a number of ODS destination (RTF and TAGSETS.EXCELXP for example), and turns off ODS LISTING (actually activates it periodically as well) ... but at the end of the program I had code to (ostensibly) return the user's environment to (hopefully) the same state in which it was before launching the program.

So currently, that part of the code looks like this:

ODS _ALL_ CLOSE;

ODS LISTING;

ODS RESULTS ON;

which with SAS 9.2 I could be pretty sure that ODS LISTING was the default state ... before the program began. But in 9.3 that is not the case.

Furthermore, I have users that will run this program that will have 9.2 (and/)or 9.3 ... and therefore I need to re-set ODS destinations to the state before the program --- and hence I need to somehow get that information at program launch so I can use it to re-set at program end.

Any clues as to how that might be accomplished?

Thanks-Allen


Accepted Solutions
Solution
‎08-01-2011 12:54 PM
SAS Employee
Posts: 6

Re: SAS 9.3-Resetting to initial "ODS state"

Posted in reply to AllenEBingham

Allen,

  For SAS 9.2, by default, ODS Listing is on and ODS HTML is off.  For SAS 9.3, by default, ODS Listing is off and ODS HTML is on.

  Here's a SAS 9.2 hack to force ODS Listing to be on prior to querying SASHELP.VDEST:

   proc template; run;

  This qualifies as a hack because there's no guarantee that it will work in future versions of SAS.

-- David Kelley, SAS

View solution in original post


All Replies
Super User
Posts: 11,343

SAS 9.3-Resetting to initial "ODS state"

Posted in reply to AllenEBingham

I don't have 9.3 yet but I would start by running PROC OPTIONS to see if any new ODS options are avaialble and then look in the online help at the automatic SYS variables to see if anything looks likely.

PROC Star
Posts: 7,492

SAS 9.3-Resetting to initial "ODS state"

Posted in reply to AllenEBingham

Take a look at:

(see How to Restore 9.2 Behavior).


SAS Employee
Posts: 6

SAS 9.3-Resetting to initial "ODS state"

Posted in reply to AllenEBingham

Query SASHELP.VDEST, e.g.:

proc print data=sashelp.vdest;run;

David Kelley, SAS

Contributor
Posts: 22

Re: SAS 9.3-Resetting to initial "ODS state"

Posted in reply to DavidK_SAS

David,

Very useful --- but somewhat problematic to actually use in practice. When I launch a 'fresh' interactive session of SAS 9.2 or 9.3, sashelp.vdest has NO observations. So my 'workaround' to that issue (is to use the proc print to actually 'populate' VDEST) in some paired code --- the 1st part is at the beginning of my macro, and the second part is at the end:

First part:

ods results off;

proc print data=sashelp.vdest;run;

data _null_;
   set sashelp.vdest;
   call symput('INIT_DEST',destination);
   call symput('INIT_STYL',style);
   stop;
run;

ODS &INIT_DEST CLOSE;

Second part:

ODS &INIT_DEST style=&INIT_STYL;

ODS RESULTS ON;

The problem with this code is that it seems to work just fine with 9.3 ... but with SAS 9.2 ... I get a Listing output in the output window of the contents of SASHELP.VDEST.

(It also assumes that there is only one active destination ... and it is the first one in VDEST)!!!

The interesting part of this that I'm wondering about it that SAS 9.2 nor 9.3 doesn't really have the Listing or HTML output active (i.e., VDEST has no obs when SAS initialized), but only has those active after 'asking' for some output (in this case via Proc Print). So really the code above is not necessarily setting things to their initial state, but seems to be as close as I can get (with my coding skills).

Any clue as to what I'm doing wrong that results in the proc print output going to the listing output window in 9.2 (seems to me the ods results off should have handled that ... and it appears to in 9.3)?

Thanks-Allen

Solution
‎08-01-2011 12:54 PM
SAS Employee
Posts: 6

Re: SAS 9.3-Resetting to initial "ODS state"

Posted in reply to AllenEBingham

Allen,

  For SAS 9.2, by default, ODS Listing is on and ODS HTML is off.  For SAS 9.3, by default, ODS Listing is off and ODS HTML is on.

  Here's a SAS 9.2 hack to force ODS Listing to be on prior to querying SASHELP.VDEST:

   proc template; run;

  This qualifies as a hack because there's no guarantee that it will work in future versions of SAS.

-- David Kelley, SAS

Contributor
Posts: 22

Re: SAS 9.3-Resetting to initial "ODS state"

Posted in reply to DavidK_SAS

Thanks---worked perfectly!!!

BTW-I'll worry about future versions of SAS when I have to cross that bridge.

Contributor
Posts: 22

Re: SAS 9.3-Resetting to initial "ODS state"

Posted in reply to DavidK_SAS

I addressed the issue of more than one active ODS destinations in the following code ... and it appears to work 'great' in both 9.2 and 9.3 (the 1st two statements are just to set things up for testing on both versions):

ods listing;
ods html;

%MACRO test;

/* Save all current system used in the macro for later re-setting to original state

   GOPTIONS that are set in the macro are reset to the default system values only */

%let sopts=
%sysfunc(getoption(missing,keyword))
%sysfunc(getoption(center))
%sysfunc(getoption(xwait))
%sysfunc(getoption(xsync))
%sysfunc(getoption(date))
%sysfunc(getoption(papersize,keyword))
%sysfunc(getoption(bottommargin,keyword))
%sysfunc(getoption(topmargin,keyword))
%sysfunc(getoption(rightmargin,keyword))
%sysfunc(getoption(leftmargin,keyword))
%sysfunc(getoption(orientation,keyword))
;

OPTIONS MPRINT;

/* Following launch of PROC TEMPLATE is to 'force' SASHELP.VDEST to have observations (if SAS just
   initialized it would not have any values */

proc template;
run;

data _null_;
   set sashelp.vdest end=last;

   call symput('INIT_DEST'||left(_n_),destination);
   call symput('INIT_STYL'||left(_n_),style);

   if last then call symput('N_DEST',LEFT(_n_));
   else;
run;

%do I = 1 %to &N_DEST %by 1;
   
   ODS &&INIT_DEST&I CLOSE;

%end;

options noxwait xsync;

ods rtf file='test.rtf';

ods results off;

/* PUT CODE FOR MACRO HERE ... THAT VARIOUSLY USES A VARIETY OF ODS DESTINATIONS */

ODS _ALL_ CLOSE;

/* Reset system options, etc. to starting values and goptions to system default values */

OPTIONS &SOPTS;
GOPTIONS reset=goptions;

/* Reset ODS destinations to original values */

%do I = 1 %to &N_DEST %by 1;
   ODS &&INIT_DEST&I style=&&INIT_STYL&I;

%end;

ODS RESULTS ON;

%MEND test;

%TEST

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 3863 views
  • 3 likes
  • 4 in conversation