- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello all,
I'm using proc univariate to create a histogram of my data, anyone knows how to output the midpoints of each bin and the corresponding percentage?
The code I use is:
proc univariate data=have; where Prep>=0.5 and Prep<130.5; histogram Prep / endpoints=(0.5 to 130 by 5); run;
By using this code, I could get the histogram, with my own defined endpoint and interval. But I don't know how to output a table (dataset) including the midpoints (or endpoints) and its percentage.
Proc freq can produce the percentage of every value in my data, but not for the bins.
Thanks!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Nope, but it does appear the documentation may be wrong. This is why I recommend the ODS TRACE options instead - run the proc with ODS TRACE ON; <procedure code> ;; ODS TRACE OFF; Then capture the name from the log.
Try Histogram instead, this works for me - SAS 9.4 TS1M4
ods table histogram=want;;
proc univariate data=sashelp.cars;
histogram mpg_highway / endpoints=(0 to 80 by 5);;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Have you tried capturing the ODS Table?
https://blogs.sas.com/content/iml/2017/01/09/ods-output-any-statistic.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Did you try it and it didn't work, or did you make that decision before trying it?
@hua wrote:
Hi Reeza, I read the link, but I don't think ODS can help to output the midpoints and percentage, because there has no options for the table I want. Or could you tell me more details about it? Thank you so much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The output wasn't named HistogramBins in the ODS TRACE step...
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Reeza, this is what I found, I think the table name is HistogramBins, did I misunderstand this option?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Nope, but it does appear the documentation may be wrong. This is why I recommend the ODS TRACE options instead - run the proc with ODS TRACE ON; <procedure code> ;; ODS TRACE OFF; Then capture the name from the log.
Try Histogram instead, this works for me - SAS 9.4 TS1M4
ods table histogram=want;;
proc univariate data=sashelp.cars;
histogram mpg_highway / endpoints=(0 to 80 by 5);;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@hua wrote:
Hi Reeza, this is what I found, I think the table name is HistogramBins, did I misunderstand this option?
You may have missed the part that the Bins or HistogramBins are only created if you use MIDPERCENTS option on the HIstogram statement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@ballardw I checked that, still doesn't work. It's a mistake in the documentation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@ballardw wrote:
@Reeza wrote:
@ballardw I checked that, still doesn't work. It's a mistake in the documentation.
ARGGH! I tend to believe the documentation for features I don't use...
I double checked, I was wrong and the documentation is sort of right.
1. It's MIDPERCENTS - not MIDPOINTS which I had tested. When you use MIDPERCENTS it does produce a table called HistogramBins. Otherwise the table is called Histogram. Which isn't listed in the list.
The inconsistency still doesn't make sense.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The easiest way to do this is to use the OUTHIST= option on the HISTOGRAM statement:
proc univariate data=sashelp.cars;
var mpg_city;
histogram mpg_city / midpoints=(5 to 65 by 10)outhist=want;
run;
proc print data=want; run;