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

Hi all!

 

I have some time series data with which I want to plot the means and medians. I am wondering if you are able to call upon the mean and median (and other functions) within the proc sgplot?

 

For instance, I have the following code where I am making 14 separate line plots :

 

%Macro Line(ET); 

proc sgplot data = Sub.Tall_M_IndEXP_Better_JB_011119;
	where ExpenseType like &ET;
	series x = Month y = mean(Value) / group= Trichot_1YR  curvelabel;
	xaxis values =(1 to 12 by 1);
run;
%mend;
%Line('Tax')
%Line('Trans')

I am getting an error when trying to utilize the function in this way that states that the variable MEAN is not found. The way around it is simply take the means before and utilize this new data, but it had me thinking if you could utilize these functions in the middle of a Proc step?

 

I was hoping that someone would be able to explain to me why or why not as I am still trying to learn the intricacies of SAS.

 

Like always, if you see any problems/inefficiencies in my code, please point it out! I am always trying to learn. Also, thank you in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

You can use the VLINE statement in SGPLOT to plot statistics. For example:

 

proc sgplot data=sashelp.class;
vline age / group=sex response=weight stat=median;
run;

SGPlot.png

PG

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

You can't use the MEAN function inside of PROC SGPLOT.

 

What you can do is run a PROC SUMMARY to compute the means (and medians and any other statistic you want) and then take the results of PROC SUMMARY and run that through PROC SGPLOT.

 

Hashtag: #PROCSUMMARYRULEZ

--
Paige Miller
PGStats
Opal | Level 21

You can use the VLINE statement in SGPLOT to plot statistics. For example:

 

proc sgplot data=sashelp.class;
vline age / group=sex response=weight stat=median;
run;

SGPlot.png

PG
joebacon
Pyrite | Level 9

Thank you kindly good sir! 

 

I went about it the long way, but have bookmarked this for the future. 🙂

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 944 views
  • 2 likes
  • 3 in conversation