BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DaveShea
Lapis Lazuli | Level 10

Hi,

 

I'm having a play with the ODS SELECT Histograms statement to get Proc Univariate to produce a table after the histogram that shows the bin sizes used by the histogram. I got the idea from the SAS documentation (see: Binning a Histogram at: http://support.sas.com/documentation/cdl/en/procstat/63104/HTML/default/viewer.htm#procstat_univaria...)

 

The first time I run my playground code shown below, I get exactly what I want, and I am very happy. However, on subsequent runs in the same SAS session, exactly the same code produces a NOTE and a WARNING indicating that the ODS object name is already in use and that SAS has added a numeric suffix to it.

  

My playground code looks like this and as it uses SASHELP.SHOES, you too can join in the fun !

 

*******************************************************************;
*Create a sub-set of SASHELP.SHOES for Sales between $10k and $100k;
*******************************************************************;
Data WORK.SHOES;
 Set SASHELP.SHOES;
 Where   SALES Between 10000 And 100000;
Run;

******************************************************************;
*Tell ODS to produce a handy table of Histogram Bin sizes after   ;
*the actual Histogram has been produced.                          ;
******************************************************************;
ODS SELECT HistogramBins MyBins;

******************************************************************;
*Tell Proc Univariate to write the bin size information out to    ;
*MyBins.                                                          ;
******************************************************************;
Title "Proc Univariate Histogram showing distribution of SALES for a sub-set of SASHELP.SHOES";
Proc Univariate Data=WORK.SHOES NoPrint;
 Var SALES;

 Histogram / MIDPERCENTS NAME="MyBins"
             ENDPOINTS =  10000 to 100000 by 10000;

Run; 
Quit;

 

When I first run the above code, the SASLOG from the Proc Univariate reports:

  

NOTE: 9867 bytes written to 
      /saswork_user/SAS_work1DF00000C36C_biffo.co.nz/SAS_work29E00000C36C_biffo.co.nz/mybins.png.
NOTE: PROCEDURE UNIVARIATE used (Total process time):
      real time           0.36 seconds
      cpu time            0.26 seconds

and my output is just what I want, one histogram and one bin size table courtesy of the:
ODS SELECT Histograms MyBins
statement.

  

However, when I run this same code again (including the ODS SELECT Histograms MyBins bit) I get the following in the SASLOG:

  

NOTE: Graph's name, MYBINS, changed to MYBINS1. MYBINS is already used or not a valid SAS name.
WARNING: Output 'MyBins' was not created.  Make sure that the output object name, label, or path is spelled correctly.  Also, 
         verify that the appropriate procedure options are used to produce the requested output object.  For example, verify that 
         the NOPRINT option is not used.
NOTE: PROCEDURE UNIVARIATE used (Total process time):
      real time           0.10 seconds
      cpu time            0.11 seconds

 

So far as I can tell, SAS seems unwilling to overwrite the original mybins.png that it created after the first run and placed into the directory that hosts the WORK library..

 

The only workaround I can think of is to comment out the ODS SELECT Histograms MyBins  for subsequent re-runs, which is messy or make a macro variable that uses the run-time to provide a unique suffix to stick on the end of MyBins which is a bit overblown.

 

I'm pretty sure that there is actually a much simpler and robust way of overcoming this problem, maybe a second statement to submit after the Proc Univariate to disassociate the name MyBins. so that it can be used on re-runs of the code.

 

I am using:

SAS 9.04.01M3P062415

SYSHOSTINFOLONG reports: Linux LIN X64 2.6.32-642.4.2.el6.x86_64 #1 SMP Mon Aug 15 02:06:41 EDT 2016 x86_64 Red Hat Enterprise Linux Server release 6.8 (Santiago)

 

Does anyone have any ideas on this one ?

 

Many thanks,

 

Downunder Dave.

Wellington

1 ACCEPTED SOLUTION
3 REPLIES 3
WarrenKuhfeld
Ammonite | Level 13

You might also use SGPLOT and ODS Graphics instead of legacy GRSEG graphics in UNIVARIATE.

DaveShea
Lapis Lazuli | Level 10

Hi Warren,

 

Thanks for your pointer.

 

Although I had been using the NAME= option I had been getting confused as to which item the SASLOG was referring to, I had been thinking that the binning table that ODS was generating had been the cause of the problem. However, your gentle nudge about using GRSEG graphics got me looking much closer and I realised that the message in the SASLOG was referring to the MYBINS item in the WORK.GSEG catalog and not the HistogramBins output table provided by ODS.

 

I've now implemented a conditional delete via Proc Catalog to remove any instances of the output item that I am just about to recreate so that my SASLOG is NOTE and WARNING free and that there is only one instance of the item in the catalog and not a series of similarly named items, MYBINS, MYBINS1, MYBINS2,.......MYBINSn etc.

 

Many thanks for your help.

 

Downunder Dave

Wellington

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 3635 views
  • 0 likes
  • 2 in conversation