Hello,
I am trying to add standard errors to my graph in gplot but unsuccessfully so far. Here is what I have: I ran repeated measures (with test as a within-subject variables [three tests] and group as a between-subject factor [3 groups]). I successfully made a graph that doesn't have standard errors using the following syntax:
proc glm data = dataset;
class Group;
model Test1 Test2 Test3 = Group;
repeated Test 3 /summary;
lsmeans Group / out=means adjust = T tdiff stderr;
run;
goptions reset=all;
symbol1 c=blue v= triangle h=2.5 i=j;
symbol2 c=red v=circle h=2.5 i=j;
symbol3 c=green v=square h=2.5 i=j;
axis1 label=(a=90 'Means');
axis2 label=('Test') value=('Test1' 'Test2' 'Test3');
proc gplot data = means;
plot lsmean*_name_ = Group / vaxis=axis1 haxis=axis2;
run;
quit;
The problem now is adding standard errors. Could anyone please help me with how to modify the syntax I have to add standard errors?
Thank you in advance.
Use SGPLOT instead with a SCATTER or SERIES statement and you can easily add the error bars. Is there any particular reason to use GPLOT? It’s pretty outdated.
See XERROR and YERROR options within the Series statement.
@Amanda_Lemon wrote:
Hello,
I am trying to add standard errors to my graph in gplot but unsuccessfully so far. Here is what I have: I ran repeated measures (with test as a within-subject variables [three tests] and group as a between-subject factor [3 groups]). I successfully made a graph that doesn't have standard errors using the following syntax:
proc glm data = dataset; class Group; model Test1 Test2 Test3 = Group; repeated Test 3 /summary; lsmeans Group / out=means adjust = T tdiff stderr; run; goptions reset=all; symbol1 c=blue v= triangle h=2.5 i=j; symbol2 c=red v=circle h=2.5 i=j; symbol3 c=green v=square h=2.5 i=j; axis1 label=(a=90 'Means'); axis2 label=('Test') value=('Test1' 'Test2' 'Test3'); proc gplot data = means; plot lsmean*_name_ = Group / vaxis=axis1 haxis=axis2; run; quit;
The problem now is adding standard errors. Could anyone please help me with how to modify the syntax I have to add standard errors?
Thank you in advance.
It doesn't seem that a SERIES statement has an option to add error bars... I am reading here: http://morgan.dartmouth.edu/Docs/sas92/support.sas.com/documentation/cdl/en/grstatproc/61948/HTML/de...
A SCATTER statement has this option but I am not sure if I can connect my dots using SCATTER?
Use both a series and scatter statement then? They’ll overlay automatically.
Got it! Thank you. One more question -- is there a way to change marker or line attributes by group? So, for example, in my syntax below all markers are filled circles but I want circles for Group 1 but triangles for Group 2 and squares for Group 3. Is it possible to change?
proc sgplot data=means_2;
scatter x = _name_ y = lsmean / group = Group yerrorlower = lower yerrorupper = upper
markerattrs = (symbol = circlefilled size = 10) datalabel = lsmean_rounded;
series x = _name_ y = lsmean / group = Group lineattrs = (pattern = solid thickness = 2);
run;
Data attribute maps are my preferred way. You can then make sure it aligns across both graphs even if one is missing a value or something like that.
@Amanda_Lemon wrote:
Got it! Thank you. One more question -- is there a way to change marker or line attributes by group? So, for example, in my syntax below all markers are filled circles but I want circles for Group 1 but triangles for Group 2 and squares for Group 3. Is it possible to change?
proc sgplot data=means_2; scatter x = _name_ y = lsmean / group = Group yerrorlower = lower yerrorupper = upper
markerattrs = (symbol = circlefilled size = 10) datalabel = lsmean_rounded; series x = _name_ y = lsmean / group = Group lineattrs = (pattern = solid thickness = 2); run;
Thank you! That's very helpful.
I ran into one more small problem. In the sgplot syntax above, I have datalabel option for scatter and I also have series on the same plot. The problem is my data labels overlap with my lines, and it doesn't look good (also difficult to see labels). Is there a way to get the software to place data labels in a way that they don't overlap with lines?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.