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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 625 views
  • 2 likes
  • 2 in conversation