The results of PROC ODSLIST and PROC ODSTEXT are displayed in reverse order if the ODS DOCUMENT destination is open


When you use ODS DOCUMENT to store the results of PROC ODSLIST or PROC ODSTEXT and another ODS destination is open at the same time, the order of the text is reversed.

To circumvent the problem, route the results to the ODS DOCUMENT destination alone. Then use PROC DOCUMENT to replay the results to any other ODS destination. 

The sample code below creates Problem.html, which is created when both the ODS DOCUMENT and ODS HTML destinations are open. The ODSLIST and ODSTEXT output is reversed. Solution.html is created by a replay of the document with PROC DOCUMENT using the ODS HTML destination. 

/* Problem: */

ods document name=test(write); 
ods html file="problem.html";
     
title "ODS DOCUMENT and HTML destinations are open";

proc odstext;
   p  "LINE 1: ODSTEXT ";
   p  "LINE 2: ODSTEXT ";
run;

proc odslist;
   item;
      p 'LINE 1: ODSLIST ';
      list;
      item 'LINE 2: ODSLIST';
      end;
   end;
run;

ods document close;
ods html close;


/*Solution:*/

ods _all_ close;
ods document name=test(write); 
     
title "only ODS DOCUMENT destination is open for creation of document itemstore";

proc odstext;
   p  "LINE 1: ODSTEXT ";
   p  "LINE 2: ODSTEXT ";
run;

proc odslist ;
   item;
      p 'LINE 1: ODSLIST ' ;
      list;
      item 'LINE 2: ODSLIST';
      end;
   end;
run;

ods document close;

ods html file="solution.html";

proc document name=test;
   replay; 
run;
quit;

ods html close;