BookmarkSubscribeRSS Feed
marieK
Obsidian | Level 7
Hi,

i created a nice Errorplot-Graphic with the Graph Template Language. I just have a problem with my X-Axis. My Axis should be labled with -60 0 60 120 180 240 300 360 Minutes but i also want to have minor tickmarks every 20 minutes (not labeled).

Can you tell me if that is possible and how i could do that?

Is it also possible to set a by-Variable so that i get errorplots for each period?


This is my code i use SAS 9.2 Phase 1:

proc template;
define statgraph fehlerplot;
begingraph;
layout overlay / xaxisopts=( Label="Time [min]" type=linear
linearopts=(tickvaluelist=(-60 0 60 120 180 240 300 360) viewmin=-60 viewmax=360) )
yaxisopts=( Label="TNSS" type=linear linearopts=( tickvaluelist=( 0 1 2 3 4 5 6 7 8 9 10 11 12 ) viewmin=0 viewmax=12 ) );;
scatterplot x=time_value y=MeanTNSS /
yerrorlower=eval(MeanTNSS - STD)
yerrorupper=eval(MeanTNSS + STD);
seriesplot x=time_value y=MeanTNSS;
endlayout;
endgraph;
end;
run;

thank you in advance!

Marie

Message was edited by: marieK Message was edited by: marieK
14 REPLIES 14
Jay54
Meteorite | Level 14
GTL does not support minor tick marks for Linear Axis. Minor tick marks are only supported for Time Axis, where the spacing is determined by the value of the INTERVAL option.

If you want ticks every 20 minutes, and know exactly where you want them and you can live with "inside" ticks (rather than the traditional outside ticks), there may be a workaround. A FRINGE plot with a column that has the values where you want the tick will give you small tick-like marks at the bottom of the graph (on the inside). You could create a column like that and add a FRINGEPLOT to your graph. Note, this only works for X or X2 axis, not Y axis. Fringe height can be adjusted.
marieK
Obsidian | Level 7
Thank you very much for your answer. I will try it the next days 🙂
marieK
Obsidian | Level 7
mmhh i think the FRINGE plot is not a good solution for me.

Do you maybe have an idea how i can do an errorplot (mean, mean+std, mean-std) in Gplot?

I tried it with:

proc sql;
create table try as
select time_value,mean(score) as mean format=6.2,
mean(score)-std(score) as std
from test
group by time
union
select time_value,mean(score) as mean format=6.2,
mean(score)+std(score) as std
from test
group by time;


symbol2 color=black
interpol=stdtj
cv=black
ci=black
line=1
value=dot;

axis1 label=('Time [min]')order=(-60 TO 360 BY 60);

axis2 label=(angle=90 'score') order=(0 to 12 by 1) value=(color=black);

proc gplot data=try;
where std NE . and time NE . ;
format mean std 3.0;
plot (std mean)*time/ overlay
haxis=axis1
vaxis=axis2;

run;
quit;

but it doesnt work properly... Any other idea?

Thanks! Marie
GraphGuy
Meteorite | Level 14
Can you elaborate some on "doesn't work properly"?


For gplot, I think you would want to have 3 response variables, instead of just two.

In pseudo-code/concept, something like ...

select time_value,mean(score) as mean format=6.2,
mean(score)-std(score) as std_lower, mean(score)+std(score) as std_upper

and then ...

symbol1 /* stuff for the =1 line */
symbol2 /* stuff for the =2 */
symbol3 /* stuff for the =3 */
plot std_upper*time=1 mean*time=2 std_lower*time=3 / overlay
GraphGuy
Meteorite | Level 14
Here's an example that has a gplot similar to what (I think) you're wanting...

http://robslink.com/SAS/democd5/revenue.htm
http://robslink.com/SAS/democd5/revenue_info.htm
marieK
Obsidian | Level 7
Hi,

thank you for your tip. now its working 🙂 do you have any idea how i join the upper and lower std and mean with a vertical line?

Like: http://web.anglia.ac.uk/numbers/biostatistics/mann_whitney/local_folder/C07fig02_ErrorPlot_Bones.jpg
GraphGuy
Meteorite | Level 14
Sounds like maybe you're wanting a "box plot"(?) Gplot symbol statement's interpol=boxcti (or other variations).

Typically with a box plot, you let the software summarize the data - do you have the un-summarized data you could use?

If you only have the summarized data, I think "proc boxplot" might be able to draw a boxplot from the summarized values, if you store them in a data set in a special way. (I'm not too familiar with "proc boxplot" though, since it's not a SAS/GRAPH proc.)
marieK
Obsidian | Level 7
Hey,

no i dont want a boxplot. i want a mean-and-error-plot (mean, mean+std, mean-std) 🙂 I also have the un-summarized data. Message was edited by: marieK
GraphGuy
Meteorite | Level 14
Hmm ... Well, since it sounds like you're pretty sure about what you want, I'll go ahead and give you the secret code to do it. Here's some code that will produce a plot exactly like the one you posted a link to:


data foo;
Sex='female'; mean=.82; error=.05; lower=mean-error; upper=mean+error; output;
Sex='male'; mean=.88; error=.045; lower=mean-error; upper=mean+error; output;
run;

data foo_anno; set foo;
xsys='2'; ysys='2'; when='b';
xc=Sex;
y=lower; function='move'; output;
y=upper; function='draw'; output;

xsys='2'; xc=Sex;
y=upper; function='move'; output;
xsys='7'; x=-2; function='draw'; output;
x=+4; function='draw'; output;

xsys='2'; xc=Sex;
y=lower; function='move'; output;
xsys='7'; x=-2; function='draw'; output;
x=+4; function='draw'; output;
run;

axis1 label=(angle=90 '95% CI Bone Density Measurement (g/square)')
order=(.75 to .95 by .05) minor=none;
axis2 label=('Sex') offset=(20,20);

symbol1 value=none interpol=none color=black;
symbol2 value=circle height=3pct interpol=none color=black;
proc gplot data=foo anno=foo_anno;
plot lower*Sex=1 mean*Sex=2 upper*Sex=1 / overlay
vaxis=axis1 haxis=axis2;
run;
marieK
Obsidian | Level 7
Hi Robert,

thanks for the code. It is working on the example, but unfortunately not on my data. It draws the mean but not the std 😞
On my x-axis i have a time-variable (-60 to 360 min). On my y-axis i have my measured value (i.e. pulse (in my data i have a score from 0 to 12)). For every measure (at beginning every 20 min then every 40 min) i want mean and std of pulse/score about all my 100 patients for every period (i have 4 periods) (period is my by-variable).

It worked well with:

proc template;
define statgraph errorplot;
begingraph;
layout overlay / xaxisopts=( Label="Time [min]" type=linear linearopts=(tickvaluelist=(-60 0 60 120 180 240 300 360) viewmin=-60 viewmax=360) )
yaxisopts=( Label="Score" type=linear linearopts=( tickvaluelist=( 0 1 2 3 4 5 6 7 8 9 10 11 12 ) viewmin=0 viewmax=12 ) );
scatterplot x=time y=MeanScore /
yerrorlower=eval(MeanScore - STD)
yerrorupper=eval(MeanScore + STD);
seriesplot x=time_value y=MeanScore;
ReferenceLine y=6 / clip=true Lineattrs=( Pattern=34);
endlayout;
endgraph;
end;
run;

proc summary data=test nway;
class time;
var Score;
by period ;
output out=weights(drop=_type_ _freq_)
mean=Mean std=STD;
run;

proc sgrender data=weights template=errorplot;
By period;
run;


But unfortunately i cant customize my axis like i told above 😞

regards,

marie
GraphGuy
Meteorite | Level 14
I think I'm going to have to have some sample data to help.
If you could send some to Robert.Allison@sas.com, that would be great...
marieK
Obsidian | Level 7
I found out by myself. juhuu 🙂 its because my variable is numeric not character and i replaced xc to x. Then everything worked. But still have a problem with my by-Variable.

This is my code now:

proc sql;
create table try as
select period, time,mean(Score) as mean format=6.2,
mean(Score)-std(Score) as std_lower, mean(Score)+std(Score) as std_upper
from final
group by time;
run;

Proc sort data=try;
by period;
run;

data test; set try;

If std_lower LT 0 Then std_lower=0;
xsys='2'; ysys='2'; when='b';
x=time;
y=std_lower; function='move'; output;
y=std_upper; function='draw'; output;


xsys='2'; x=time;
y=std_upper; function='move'; output;
xsys='7'; x=-2; function='draw'; output;
x=+4;function='draw'; output;

If std_lower GT 0 Then do;
xsys='2'; x=time;
y=std_lower; function='move'; output;
xsys='7'; x=-2; function='draw'; output;
x=+4; function='draw'; output; end;
run;


axis1 LABEL=(angle=90 Score') Order=(0 1 2 3 4 5 6 7 8 9 10 11 12) minor=none;
axis2 LABEL=('Time [min]') Order=(-60 to 360 by 60)offset=(,2);

symbol1 value=none interpol=none color=black;
symbol2 value=circle height=3pct interpol=none color=black;
proc gplot data=try anno=test;
plot std_lower*time=1 mean*time=2 std_upper*time=1 / overlay vaxis=axis1 haxis=axis2 hminor=2 vref=6 LVREF=20;
run;

quit;

If i put a by-Statement to proc gplot i get for every period the same Graph. Do you have any idea how i can draw a Graph for each period with the corresponding data (without having an own dataset for each period)? Message was edited by: marieK
GraphGuy
Meteorite | Level 14
Hmm ... by-processing with annotate can be a bit tricky...

Try moving the anno= from the gplot line:

proc gplot data=try anno=test;
plot std_lower*time_value=1 mean*time_value=2 std_upper*time_value=1 / overlay vaxis=axis1 haxis=axis2 hminor=2 vref=6 LVREF=20;


To the options section (after the '/') in the plot statement:

proc gplot data=try;
plot std_lower*time_value=1 mean*time_value=2 std_upper*time_value=1 / anno=test overlay vaxis=axis1 haxis=axis2 hminor=2 vref=6 LVREF=20;
marieK
Obsidian | Level 7
doesnt work 😞

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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