BookmarkSubscribeRSS Feed
jheinsius
Calcite | Level 5

Very new to SAS! I currently have a plot with all my data points but I want to just have averages. Is there a way to code in that I want to do an average of a variable within the sgplot procedure.  I thought I could just do y=AVE(Variable Name) but that didn't work. Then I thought I could create the variables almost with an average but I don't know how to do that. 

 

Any ideas?? Sorry if this is something super easy I just couldn't find an answer when googling. Thank you!

 

proc sgplot data=WORK.IMPORT1;
title 'TITLE';
scatter x=Variable1 y=Varaible2 / group=Variable3;
run;

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Averages of your data broken down by what? You really haven't given us a lot to work with here. How about some more details?

--
Paige Miller
jheinsius
Calcite | Level 5

Sorry about that. Im not really sure how to describe things just yet. I have two categorical variables (from my code Variable 2 and Variable 3) So i want the averages of all Variable1 data, for groups 1-4 of Variable3, throughout 6 phases of Variable2. So my y axis would only have 6 points, and in the chart i would only have four points associated there being the averages of Variable1 for each group of Variable3. 

 

I feel like Im not saying this very clearly but am not really sure how else to describe this. Im sorry! 

PaigeMiller
Diamond | Level 26

How about using PROC SUMMARY to compute the 24 means you want, then PROC SGPLOT with the DOT command to do the plotting.

--
Paige Miller
jheinsius
Calcite | Level 5

 

Ok this was my code and I am getting the error: "Attempting to overlay incompatible plot or chart types"

 

 

proc sgplot data=WORK.IMPORT1;
title 'TITLE';
scatter x=Variable1 y=Variable2 / group=Variable3;
DOT Variable3 / STAT=Mean RESPONSE=Variable2;
run;

Reeza
Super User

Certain graph types allow you to summarize the data while graphing it, unfortunately scatter plots are not one of them.

 

You will need to first summarize your data using PROC MEANS and capture that in an output table. Then use that with PROC SGPLOT. 

 

Here's an example of how to use PROC MEANS and get an output data set.

https://github.com/statgeek/SAS-Tutorials/blob/master/proc_means_basic.sas

 


@jheinsius wrote:

Very new to SAS! I currently have a plot with all my data points but I want to just have averages. Is there a way to code in that I want to do an average of a variable within the sgplot procedure.  I thought I could just do y=AVE(Variable Name) but that didn't work. Then I thought I could create the variables almost with an average but I don't know how to do that. 

 

Any ideas?? Sorry if this is something super easy I just couldn't find an answer when googling. Thank you!

 

proc sgplot data=WORK.IMPORT1;
title 'TITLE';
scatter x=Variable1 y=Varaible2 / group=Variable3;
run;


 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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