Data visualization with SAS programming

ODS Graphics produces unwanted output

Occasional Contributor
Posts: 8

ODS Graphics produces unwanted output


I'm having problems with ODS graphics on/off recently. it produces unwanted output that was from previous codes.

Here is the code :

ods graphics off;

proc univariate data=test noprint;  

histogram ttr  / cfill=blue cframe=gwh vaxis=0 to 35 by 5, midpoints=0 to 200 by 10 normal( mu=est sigma=est color=RED w=1);

inset n mean (5.3) std(5.3) p10 (5.3) median (5.3) p90 (5.3) /pos=ne header='Summary Statistics' HEIGHT=3 cfill = bwh cframe=black;


ods graphics on;
%graphic_template(1, 1, 1, 1, &ExcelPath, Appendix 3.2.4-02 ); 

Could anyone help me with it ? I know the code is incomplete, but i think it's sufficient for you to lock in where the problem is .

Thanks !

Posts: 8,645

Re: ODS Graphics produces unwanted output

Hi: What is inside your %graphic_template macro program? The PROC UNIVARIATE step?


Occasional Contributor
Posts: 8

Re: ODS Graphics produces unwanted output

Hi Cynthia,

Thanks for replying.

%MACRO graphic_template(across, down, startNum, endNum, oPath,oFileName);                                                                                                 


  %let npanels=%eval(&down*&across);                                                                                                                                      


  data numgraf;                                                                                                                                                           

      ymult=100/&down;                         /* Y increment for panels. */                                                                                              

      xmult=100/&across;                       /* X increment for panels. */                                                                                              


      data coord;                                                                                                                                                            

      set numgraf;                                                                                                                                                        

      do x=0 to (100-xmult) by xmult;     /* Calculate X coordinate values. */                                                                                            

         llx=x;                           /* Lower-left X.                  */                                                                                            

         ulx=x;                           /* Upper-left X.                  */                                                                                            

         urx=x+xmult;                     /* Upper-right X.                 */                                                                                            

         lrx=x+xmult;                     /* Lower-right X.                 */                                                                                            

         do y=0 to (100-ymult) by ymult;  /* Calculate Y coordinate values. */                                                                                            

            lly=y;                        /* Lower-left Y.                  */                                                                                            

            uly=y+ymult;                  /* Upper-left Y.                  */                                                                                            

            ury=y+ymult;                  /* Upper-right Y.                 */                                                                                            

            lry=y;                        /* Lower-right Y.                 */                                                                                            






   proc sort data=coord;                                                                                                                                                  

      by descending y;                                                                                                                                                    



   data mccoord;                                                                                                                                                          

      set coord end=eof;                                                                                                                                                  

      call symput('llx'||left(_n_),llx);                                                                                                                                  

      call symput('ulx'||left(_n_),ulx);                                                                                                                                  

      call symput('urx'||left(_n_),urx);                                                                                                                                  

      call symput('lrx'||left(_n_),lrx);                                                                                                                                  

      call symput('lly'||left(_n_),lly);                                                                                                                                  

      call symput('uly'||left(_n_),uly);                                                                                                                                  

      call symput('ury'||left(_n_),ury);                                                                                                                                  

      call symput('lry'||left(_n_),lry);                                                                                                                                  

      if eof then call symput('total',_n_);                                                                                                                               


%let replay_num=&startNum:1;                                                                                                                                              

%let n=2;                                                                                                                                                                 

%do i=%eval(&startNum+1) %to &endNum;                                                                                                                                     

        %let nnn=&i:&n;                                                                                                                                                   

        %let replay_num=&replay_num &nnn;                                                                                                                                 

        %let n=%eval(&n+1);                                                                                                                                               


%put &replay_num;                                                                                                                                                         

ods listing;                                                                                                                                                              

proc greplay nofs igout=work.gseg tc=work.templt  template =Spec&npanels ;                                                                                                

   tdef spec&npanels                                                                                                                                                      


filename out1 "&oPath.\&oFileName..emf";                                                                                                                                  

goptions device=gif gsfname=out1 gsfmode=replace  hsize = 8.33  vsize =6.03;                                                                                              

  treplay &replay_num ;                                                                                                                                                   


ods listing close;                                                                                                                                                        


Here is the code, towards the end there is a proc greplay statement, and from the output, that's where the problem is showing. For each result, there is a univariate output(histogram) , which is correct, but also a greplay output, which is the wrong one.

Note that if i reboot SAS, so that all SAS temp files would be gone, and rerun this code, i would get the desired graphs, I think it must be with the setting of ODS or something. Hope you could help. 

Posts: 8,645

Re: ODS Graphics produces unwanted output


  It's not a setting with ODS, but it is the fact that GREPLAY and SAS/GRAPH have their own numbering system for the catalog entries that are made by the procedures. When you use SAS/GRAPH to create output or GREPLAY, each of your graph images and replayed graph images gets a name and a number. The reason it works after you log off and log back on is that the temporary files in WORK.GSEG get deleted. You can mimic this by "cleaning up" WORK.GSEG before you submit your macro program.

  This would delete everything in the current WORK.GSEG catalog and reset all the GOPTIONS:

proc greplay igout = work.gseg nofs;
  delete _all_;

goptions reset=all;

  And, this is another way to completely get rid of WORK.GSEG:

proc catalog cat=work.gseg kill force;



Just remember that ODS GRAPHICS output is NOT written to WORK.GSEG, so if you have also used ODS GRAPHICS to make images, you may or may not want to clean them up as well. But since GREPLAY only works with SAS/GRAPH, it seems likely that you will want to clean out WORK.GSEG.


Occasional Contributor
Posts: 8

Re: ODS Graphics produces unwanted output

Thanks Cynthia, this is very helpful !

Post a Question
Discussion Stats
  • 4 replies
  • 2 in conversation