DATA Step, Macro, Functions and more

How to output histogram database

Accepted Solution Solved
Reply
Contributor hua
Contributor
Posts: 66
Accepted Solution

How to output histogram database

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
Solution
a week ago
Super User
Posts: 19,860

Re: How to output histogram database

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;

View solution in original post


All Replies
Super User
Posts: 19,860

Re: How to output histogram database

Contributor hua
Contributor
Posts: 66

Re: How to output histogram database

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!
Super User
Posts: 19,860

Re: How to output histogram database

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!

 

Contributor hua
Contributor
Posts: 66

Re: How to output histogram database

Yes, I tried. I use "ODS OUTPUT HistogramBins=output;", but it doesn't work here.
Super User
Posts: 19,860

Re: How to output histogram database

The output wasn't named HistogramBins in the ODS TRACE step...

Super User
Posts: 19,860

Re: How to output histogram database

You can also check the documentation for the ODS table name.
Contributor hua
Contributor
Posts: 66

Re: How to output histogram database

QQ图片20171113162955.png

Hi Reeza, this is what I found, I think the table name is HistogramBins, did I misunderstand this option? 

Solution
a week ago
Super User
Posts: 19,860

Re: How to output histogram database

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;
Contributor hua
Contributor
Posts: 66

Re: How to output histogram database

Yes, the Histogram works. And the log do show "histogram" when I use ods trade on and ods trade off. Sorry, I didn't realized I could capture the name before. Thank you for help! thank you so much, Reeza.
Super User
Posts: 11,343

Re: How to output histogram database


hua wrote:

QQ图片20171113162955.png

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.

Super User
Posts: 19,860

Re: How to output histogram database

@ballardw I checked that, still doesn't work. It's a mistake in the documentation. 

Super User
Posts: 11,343

Re: How to output histogram database


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...

Super User
Posts: 19,860

Re: How to output histogram database


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. 

SAS Super FREQ
Posts: 3,755

Re: How to output histogram database

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;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 19 replies
  • 142 views
  • 6 likes
  • 4 in conversation