BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hua
Obsidian | Level 7 hua
Obsidian | Level 7

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! 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

19 REPLIES 19
hua
Obsidian | Level 7 hua
Obsidian | Level 7
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!
Reeza
Super User

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!

 

hua
Obsidian | Level 7 hua
Obsidian | Level 7
Yes, I tried. I use "ODS OUTPUT HistogramBins=output;", but it doesn't work here.
Reeza
Super User

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

Reeza
Super User
You can also check the documentation for the ODS table name.
hua
Obsidian | Level 7 hua
Obsidian | Level 7

QQ图片20171113162955.png

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

Reeza
Super User

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;
hua
Obsidian | Level 7 hua
Obsidian | Level 7
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.
ballardw
Super User

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

Reeza
Super User

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

ballardw
Super User

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

Reeza
Super User

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

Rick_SAS
SAS Super FREQ

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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