BookmarkSubscribeRSS Feed
DarekB
Calcite | Level 5

Hello,

I would like to draw a histogram of one interval variable in SAS that also would present a mean of another variable in the bin of the histogram. I'm attaching a pdf to give you an idea what I would like to get.

Regards,

DarekB

6 REPLIES 6
FreelanceReinh
Jade | Level 19

Hello @DarekB and welcome to the SAS Support Communities,

 

You could create an overlay chart as is described here: https://blogs.sas.com/content/graphicallyspeaking/2018/02/05/dual-response-axis-bar-line-overlay-par...

 

This blog (Graphically Speaking) presents a great variety of plots that can be produced with SAS ODS Graphics.

DarekB
Calcite | Level 5

Thank you very much @FreelanceReinh

 

I have one question. Instead of a bar plot with categories I would like to have a histogram of an interval variable drawn by SAS and then a line on the histogram

FreelanceReinh
Jade | Level 19

It seems that more advanced techniques (PROC TEMPLATE) are required to overlay a curve on a histogram:

https://blogs.sas.com/content/iml/2013/04/24/overlay-density-curve-on-a-histogram.html.

 

I'm not really familiar with PROC TEMPLATE. So, if I were to produce that graph, I would consider creating a bar chart based on the histogram data. For example, if you create the original histogram with PROC UNIVARIATE, you can write the histogram data to a dataset:

https://communities.sas.com/t5/Statistical-Procedures/Exporting-Histogram-Data-to-Excel/m-p/388279#M....

Reeza
Super User

A histogram is a bar chart with no spaces between the bars. Add that option to the blog posts and it's essentially the same thing.

 


@DarekB wrote:

Thank you very much @FreelanceReinh

 

I have one question. Instead of a bar plot with categories I would like to have a histogram of an interval variable drawn by SAS and then a line on the histogram


 

DarekB
Calcite | Level 5

@Reezato have a histogram you have to calculate bins (categories) based on the interval variable sample distribution. Then you draw a bar plot with calculated bins as categories.

Reeza
Super User
No disagreement there. Is the calculating the bins the issue? Although SAS will do that automatically with PROC UNIVARIATE or other procedures, I'm sure you're aware that bin selection can change the graph a lot. Anyways, you do need to precalculate the numbers and then create the graph for a combined bar plot anyways. You could run PROC UNIVARIATE and capture the output and use that as your feeder, but it's still a two step process.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 6 replies
  • 1772 views
  • 0 likes
  • 3 in conversation