Help using Base SAS procedures

Proc Gchart (Want to know about Backend Process)

Posts: 72

Proc Gchart (Want to know about Backend Process)

When I create a histogram through Proc Gchart I observed some values on horizontal scale called (Midpoints).

Anybody please help me how they will get created?  (on any data set)  How those values are calculated?

If we use discrete as a option. it is easy to understand.

Thanks in Advance !!

Posts: 9,368

Re: Proc Gchart (Want to know about Backend Process)

Posted in reply to DR_Majeti


  I'd recommend reading about MIDPOINTS in the SAS/GRAPH documentation. My guess is that your chart variable was numeric. For a numeric variable, SAS/GRAPH tries to "help" you by treating a numeric variable as a continuous variable and so it calculates values to represent the bars, which might be good as a first pass on a variable that represented HEIGHT or WEIGHT, but would not be good for a variable such as AGE. AGE truly is discrete, in other words, you want a bar for each unique value of AGE. But, for example, you would NOT want a bar for each unique value of HEIGHT or WEIGHT. So MIDPOINTS is how PROC GCHART avoids making too many bars for numeric variables. When PROC GCHART calculates MIDPOINTS for you, the word "MIDPOINTS" is usually added to the label under the graph. When you use DISCRETE as an option, you should see that the word MIDPOINTS goes away...this shows that you are in control of the bar values through the use of options.

  There are many different ways to specify your own MIDPOINTS for numeric variables (such as HEIGHT or WEIGHT), and they are all documented. But for variables like AGE, the quickest way to use the unique values for the bars is to specify the DISCRETE option on the VBAR statement.

  There are also other ways to create histograms with SAS, depending on what you want. One way is with PROC FREQ. The other way is with the SGPLOT procedure. You will need to have SAS 9.2 or higher to run examples 3 and 4 in the code below.


ods html path='c:\temp' (url=none)

         file='two_histo.html' style=analysis;


proc gchart data=sashelp.class;

  title '1) Default MIDPOINTS for Numeric Var';

  vbar age;




proc gchart data=sashelp.class;

  title '2) Using the DISCRETE Option';

  vbar age / discrete;




ods graphics on;

proc freq data=sashelp.class;

  title '3) Graphs with PROC FREQ';

  tables age / plots=all;


ods graphics off;


proc sgplot data=sashelp.class;

  title '4) Histogram with SGPLOT';

  histogram age;

  density age / type=normal;

  density age / type=kernel;



ods html close;


Posts: 72

Re: Proc Gchart (Want to know about Backend Process)

Posted in reply to Cynthia_sas

Thanks Cynthia.. I will come on back this after working on whatever you suggested me..

Ask a Question
Discussion stats
  • 2 replies
  • 2 in conversation