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

I have a dataset that has a Month variable, and calculated the medians of the 5 other variables in my dataset.

proc means data = final4 noprint;
	by Month;
	var High Low Precip Snow SnowDepth;
	output out = final5(drop=_type_ _freq_)
		     median = /autoname;
	
run;

I output it to the temp dataset final5.  Now I need to plot a barchart (histogram) of one of my variables by month, so it would look like Month on the x axis and, let's say Snow, on the yaxis, and It would plot the medians of Snow for each month.  I have tried proc gplot and proc splot, but the stat functions they have do not include the median, and I can't find another way to plot a barchart that would include both variables.

 

I appreciate any help anyone can provide.

 

Thanks!

 

Adam

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Look at using VBARPARM instead of VBAR. 

 


@BoboTheFool wrote:

I figured it out, kinda backed into a solution.  Since I saved the dataset as medians of each month for each variable, when I plotted vbar Month / response = Precip_Median; it plotted what I needed, sort of by default.


 

View solution in original post

9 REPLIES 9
Reeza
Super User

Show the code you tried, specifically the SGPlot code. 

You have summary data so you shouldn’t be requesting any statistics, just do a bar plot instead. 

 

A histogram shows a distribution, your graph would not be called a histogram.  

 

PS. Please mark your previous questions as answered. 


@BoboTheFool wrote:

I have a dataset that has a Month variable, and calculated the medians of the 5 other variables in my dataset.

proc means data = final4 noprint;
	by Month;
	var High Low Precip Snow SnowDepth;
	output out = final5(drop=_type_ _freq_)
		     median = /autoname;
	
run;

I output it to the temp dataset final5.  Now I need to plot a barchart (histogram) of one of my variables by month, so it would look like Month on the x axis and, let's say Snow, on the yaxis, and It would plot the medians of Snow for each month.  I have tried proc gplot and proc splot, but the stat functions they have do not include the median, and I can't find another way to plot a barchart that would include both variables.

 

I appreciate any help anyone can provide.

 

Thanks!

 

Adam


 

BoboTheFool
Calcite | Level 5

I figured it out, kinda backed into a solution.  Since I saved the dataset as medians of each month for each variable, when I plotted vbar Month / response = Precip_Median; it plotted what I needed, sort of by default.

Reeza
Super User

Look at using VBARPARM instead of VBAR. 

 


@BoboTheFool wrote:

I figured it out, kinda backed into a solution.  Since I saved the dataset as medians of each month for each variable, when I plotted vbar Month / response = Precip_Median; it plotted what I needed, sort of by default.


 

BoboTheFool
Calcite | Level 5

Thanks @Reeza .  A quick question - When I run a proc means and get the statistics (mean, median, etc,), is there a way I can rename the mean descriptor?  And example.  Proc means labels Q1 as the lesser quantile or something like that.  Is there a way I can change that label to just Q1?

Reeza
Super User
You're using the autoname option which automatically names the variables. Remove that and put the names after the equal size.

output out=summary1 q1 = lesser_quantile q3=upper_quantile;

Honestly, I almost never use the OUTPUT table, I prefer the ODS format instead.

This example illustrates the two methods and I find the second usually works better for what I need 90% of the time.

https://github.com/statgeek/SAS-Tutorials/blob/master/proc_means_basic.sas
BoboTheFool
Calcite | Level 5

so here is my code @Reeza 

proc means data = final4 Q1 median Q3;
	var High Low Precip Snow SnowDepth;
	
	label High = "High";
	label Low = "Low";
	label Precip = "Precip";
	label Snow = "Snow";
	label SnowDepth = "SnowDepth";

title "Quantiles of the Weather Variables of 2018";		
run;

I would like to change the lower and upper quantile names to Q1 and Q3 for the below output

 

BoboTheFool
Calcite | Level 5

Quantiles of the Weather Variables of 2018

The MEANS Procedure

 Variable Label Lower Quartile Median Upper Quartile

High
Low
Precip
Snow
SnowDepth
High
Low
Precip
Snow
SnowDepth
32.0000000
16.0000000
0
0
0
51.1000000
30.9000000
0
0
0
75.9000000
55.9000000
0.0200000
0
0
ballardw
Super User

@BoboTheFool wrote:

Quantiles of the Weather Variables of 2018

The MEANS Procedure

 Variable Label Lower Quartile Median Upper Quartile

High
Low
Precip
Snow
SnowDepth
High
Low
Precip
Snow
SnowDepth
32.0000000
16.0000000
0
0
0
51.1000000
30.9000000
0
0
0
75.9000000
55.9000000
0.0200000
0
0

Send output to the LISTING destination and then copy from the output window into a code box. The above is essentially unreadable.

 

The question remains, are you sending the results to a data set or not? At the top of the topic you were but now it appears that you are not.

You can add a rename dataset option on the output to change the NAMES of variables.

If you want the proc means output directly to be "prettier" you might try one of the report procedures such as Proc Tabulate or Report that will allow setting labels and formats "nicer" than proc means.

Reeza
Super User
You cannot change the default output without changing the proc means display template. WI do not recommend that option, it's complex and a pain.

What you can do is capture the table and then use PROC PRINT to control the displayed output exactly as you'd like.

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
  • 9 replies
  • 815 views
  • 0 likes
  • 3 in conversation