BookmarkSubscribeRSS Feed
Amanda_Lemon
Quartz | Level 8

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. 

6 REPLIES 6
Reeza
Super User

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. 


 

Amanda_Lemon
Quartz | Level 8

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?

Reeza
Super User

Use both a series and scatter statement then? They’ll overlay automatically. 

 

Amanda_Lemon
Quartz | Level 8

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;
Reeza
Super User

http://documentation.sas.com/?docsetId=grstatproc&docsetTarget=p18q268a3zxcl3n11lnnnq4cme8r.htm&docs...

 

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;

 

Amanda_Lemon
Quartz | Level 8

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: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 6 replies
  • 1655 views
  • 0 likes
  • 2 in conversation