SAS Studio

Write and run SAS programs in your web browser
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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 1556 views
  • 0 likes
  • 3 in conversation