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

I was trying to create histograms for the sashelp.cars data set, and I want price (MSRP) binned into 5 groups and I also want to display Origin and Type on the plot. However, my resulting display just isn't right and I'm not sure what I'm doing wrong. A quick proc freq shows that Sedans are by far the most common Type of car in the three car manufacturing Origins, but the stacked plot shows USA mostly has Sports cars. Sports is the least common in all regions so it seems my charts are somehow backwards.

I don't have to use SGPanel if there is something better that you recommend, but I do want to be able to bin my continuous variable (price in this case). Thanks for your help 🙂

 

proc freq data=sashelp.cars; 
tables type*origin;
run;
proc sgpanel data=sashelp.cars;
	where type in('SUV','Sedan','Sports');
	panelby origin;
	histogram msrp / group=type nbins=5;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

See if this makes more sense.

 

proc sgpanel data=sashelp.cars;
	where type in('SUV','Sedan','Sports');
	panelby origin;
	histogram msrp / group=type scale=count nbins=5;
run;

The default for the scale is percent and with grouped values I think the denominator is not all cars but the type of car. So roughly 37 percent of Sports cars are in the bin with the price of $50,000

View solution in original post

2 REPLIES 2
ballardw
Super User

See if this makes more sense.

 

proc sgpanel data=sashelp.cars;
	where type in('SUV','Sedan','Sports');
	panelby origin;
	histogram msrp / group=type scale=count nbins=5;
run;

The default for the scale is percent and with grouped values I think the denominator is not all cars but the type of car. So roughly 37 percent of Sports cars are in the bin with the price of $50,000

Buzzy_Bee
Quartz | Level 8

Perfect - that's exactly what I was looking for. The example I was following on the documention.sas.com website showed their option as "stat=percent" so I had tried changing it to stat=freq, but kept getting error messages and I couldn't find better examples on the documention.sas.com website. Your solution using scale=count is the correct option to use to get it display how I wanted it. Thank you.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 868 views
  • 2 likes
  • 2 in conversation