Hi.
I am usually a Stata user, so forgive my novice status with SAS. I am using SAS On Demand for the analysis for a crossover study using an AB/BA design.
My code is relatively simple, namely:
------------------------
data trial;
length Drug1 $ 9;
length Drug2 $ 9;
input Patient Drug1 $ Drug2 $ Pain1 Pain2 @@;
datalines;
1 A B 7 1
2 B A 3 3
.......etc
64 B A 6 3
proc print data=trial;
run;
ods graphics on;
proc ttest data=trial plots=interval;
var Pain1 Pain2 / crossover= (Drug1 Drug2);
run;
ods graphics off;
------------------------
One of the graphs from the output is for Profiles over Treatment for (Pain1, Pain2).
I attach this output and would like the y axis to go from 0-10 rather than 0-9 as SAS has done.
I can't seem to get ODS Graphics Editor to work, so was wondering if there was a simple piece of code for the one thing within one graph that I want to change.
Many thanks in advance.
Here we go!
Submit this program:
https://go.documentation.sas.com/api/docsets/statug/14.2/content/statug_code_tteex04.htm?locale=nl
, but first put an extra 2 statements:
ods path show;
ods trace on;
just below the:
ods graphics on; statement.
You will notice immediatly it's the same program as yours (but other data, ... full data!).
Finish the program with the:
ods trace off; statement.
The plot you are interested in (named "ProfilesOverTrt") is the last but two output objects:
Output Added:
-------------
Name: ProfilesOverTrt
Label: Profiles over Treatment
Template: Stat.TTest.Graphics.ProfilesOverTreatmentC
Path: Ttest.PEF1_PEF2.ProfilesOverTrt
-------------
We can see the name of ALL the output objects (tables and graphs / plots) in the LOG-screen thanks to the ODS TRACE ON; statement.
I will soon change the y-axis (from 100 to 400 by 100) to (from 50 to 450 by 50)!
Let's now have a look at the graphical template that was used to produce this particular original plot (in its current format):
The template code (in GTL -> Graphical Template Language) will be published in the LOG-screen if you submit these statements:
options ls=200 nocenter;
proc template;
path sashelp.tmplmst;
list stat.ttest.Graphics / sort=path descending;
source stat.ttest.Graphics.ProfilesOverTreatmentC;
run;
Starting from these statements I will create the new plot with the altered Y-axis. The options we have to change are behind
yaxisopts= (layout statement).
Here is the new code for the template:
options ls=200 nocenter;
proc template;
path sashelp.tmplmst;
source stat.ttest.Graphics.ProfilesOverTreatmentC;
run;
proc template ;
define statgraph Stat.Ttest.Graphics.ProfilesOverTreatmentC;
notes "Subject-profiles plot over treatment (crossover)";
dynamic _Y _YMEAN _VARNAME1 _VARNAME2 _OBSVAR _TIPVAR _byline_ _bytitle_ _byfootnote_;
BeginGraph;
entrytitle "Profiles over Treatment for (" _VARNAME1 ", " _VARNAME2 ")";
layout overlay /
xaxisopts=(type=discrete offsetmin=autocompress offsetmax=autocompress discreteopts=(tickvaluefitpolicy=rotate))
yaxisopts=(label="Response" griddisplay=on
linearopts=( /* linear axis (not log axis) */
viewmin=0 /* smallest value to display */
viewmax=600 tickvaluelist=(50 100 150 200 250 300 350 400 450)));
seriesplot X=TREATMENT Y=_Y / group=_OBSVAR index=SEQUENCE lineattrs=(thickness=1)
datatransparency=.5 rolename=(varname=_TIPVAR sn=SEQNAME) tip=(x varname y sn group);
seriesplot X=TREATMENT Y=_YMEAN / group=SEQNAME index=SEQUENCE lineattrs=(thickness=1)
datatransparency=.5 rolename=(varname=_TIPVAR sn=SEQNAME) tip=(x varname y sn group) name="MiniSeries";
seriesplot X=TREATMENT Y=_YMEAN / group=MEANSEQNAME index=SEQUENCE lineattrs=(thickness=3) rolename=(varname=_TIPVAR sn=SEQNAME)
tip=(x varname y sn) name="Means";
discreteLegend "MiniSeries" "Means" / title="Treatment Sequence" across=1 location=outside halign=right valign=center;
endlayout;
if (_BYTITLE_)
entrytitle _BYLINE_ / textattrs=GRAPHVALUETEXT;
else
if (_BYFOOTNOTE_)
entryfootnote halign=left _BYLINE_;
endif;
endif;
EndGraph;
end;
run;
Then run
https://go.documentation.sas.com/api/docsets/statug/14.2/content/statug_code_tteex04.htm?locale=nl
again.
You will notice the new wanted Y-axis in the output (other scaling).
In the LOG_screen you can also read in which item store the new template was put:
NOTE: STATGRAPH 'Stat.Ttest.Graphics.ProfilesOverTreatmentC' has been saved to: SASUSER.TEMPLAT
How to revert back to the original template??
Type LIBNAME as a command -> this will tell you about the physical location of your SASUSER directory.
Go to that directory in the windows explorer and delete the file "templat.sas7bitm".
Important remark: There is a much more elegant way in SAS itself to delete this "templat.sas7bitm" item store but I don't remember how.
Now submit again:
https://go.documentation.sas.com/api/docsets/statug/14.2/content/statug_code_tteex04.htm?locale=nl
and you will see that everything is back to normal (the default template is used). The original Y-axis is back!
More info on
ODS PATH SHOW
More info on
the yaxisopts= for axis layout
Hope this helps,
Koen
Hello,
Why don't you make the plot yourself with PROC SGPLOT (Statistical Graphics procedure)?
Then you have full control.
You won't even need the Graphic Template Language (GTL).
One of the statements in your PROC SGPLOT would be:
yaxis min=0 max=10 integer grid label='Response';
OR
YAXIS LABEL = 'Response' GRID VALUES = (0 TO 10 BY 1);
Cheers,
Koen
Hi Koen.
Many thanks for your reply.
Having been through the help file online for PROC SGPLOT, I can't seem to find the plot I am after in the options, which is the one of the several produced with PROC TTEST that I attached as an image in my post.
Do you know which graph option that one would be within PROC SGPLOT? As I say, I'm a total SAS novice and just want to change the y axis scale from 0-9 to 0-10 of that one graph.
Many thanks again in advance.
Regards, Dilraj
Hello,
I will answer you tomorrow.
It will be a very long answer with lots of code as the template for showing that particular plot (named "ProfilesOverTrt") has to be changed!
Koen
Here we go!
Submit this program:
https://go.documentation.sas.com/api/docsets/statug/14.2/content/statug_code_tteex04.htm?locale=nl
, but first put an extra 2 statements:
ods path show;
ods trace on;
just below the:
ods graphics on; statement.
You will notice immediatly it's the same program as yours (but other data, ... full data!).
Finish the program with the:
ods trace off; statement.
The plot you are interested in (named "ProfilesOverTrt") is the last but two output objects:
Output Added:
-------------
Name: ProfilesOverTrt
Label: Profiles over Treatment
Template: Stat.TTest.Graphics.ProfilesOverTreatmentC
Path: Ttest.PEF1_PEF2.ProfilesOverTrt
-------------
We can see the name of ALL the output objects (tables and graphs / plots) in the LOG-screen thanks to the ODS TRACE ON; statement.
I will soon change the y-axis (from 100 to 400 by 100) to (from 50 to 450 by 50)!
Let's now have a look at the graphical template that was used to produce this particular original plot (in its current format):
The template code (in GTL -> Graphical Template Language) will be published in the LOG-screen if you submit these statements:
options ls=200 nocenter;
proc template;
path sashelp.tmplmst;
list stat.ttest.Graphics / sort=path descending;
source stat.ttest.Graphics.ProfilesOverTreatmentC;
run;
Starting from these statements I will create the new plot with the altered Y-axis. The options we have to change are behind
yaxisopts= (layout statement).
Here is the new code for the template:
options ls=200 nocenter;
proc template;
path sashelp.tmplmst;
source stat.ttest.Graphics.ProfilesOverTreatmentC;
run;
proc template ;
define statgraph Stat.Ttest.Graphics.ProfilesOverTreatmentC;
notes "Subject-profiles plot over treatment (crossover)";
dynamic _Y _YMEAN _VARNAME1 _VARNAME2 _OBSVAR _TIPVAR _byline_ _bytitle_ _byfootnote_;
BeginGraph;
entrytitle "Profiles over Treatment for (" _VARNAME1 ", " _VARNAME2 ")";
layout overlay /
xaxisopts=(type=discrete offsetmin=autocompress offsetmax=autocompress discreteopts=(tickvaluefitpolicy=rotate))
yaxisopts=(label="Response" griddisplay=on
linearopts=( /* linear axis (not log axis) */
viewmin=0 /* smallest value to display */
viewmax=600 tickvaluelist=(50 100 150 200 250 300 350 400 450)));
seriesplot X=TREATMENT Y=_Y / group=_OBSVAR index=SEQUENCE lineattrs=(thickness=1)
datatransparency=.5 rolename=(varname=_TIPVAR sn=SEQNAME) tip=(x varname y sn group);
seriesplot X=TREATMENT Y=_YMEAN / group=SEQNAME index=SEQUENCE lineattrs=(thickness=1)
datatransparency=.5 rolename=(varname=_TIPVAR sn=SEQNAME) tip=(x varname y sn group) name="MiniSeries";
seriesplot X=TREATMENT Y=_YMEAN / group=MEANSEQNAME index=SEQUENCE lineattrs=(thickness=3) rolename=(varname=_TIPVAR sn=SEQNAME)
tip=(x varname y sn) name="Means";
discreteLegend "MiniSeries" "Means" / title="Treatment Sequence" across=1 location=outside halign=right valign=center;
endlayout;
if (_BYTITLE_)
entrytitle _BYLINE_ / textattrs=GRAPHVALUETEXT;
else
if (_BYFOOTNOTE_)
entryfootnote halign=left _BYLINE_;
endif;
endif;
EndGraph;
end;
run;
Then run
https://go.documentation.sas.com/api/docsets/statug/14.2/content/statug_code_tteex04.htm?locale=nl
again.
You will notice the new wanted Y-axis in the output (other scaling).
In the LOG_screen you can also read in which item store the new template was put:
NOTE: STATGRAPH 'Stat.Ttest.Graphics.ProfilesOverTreatmentC' has been saved to: SASUSER.TEMPLAT
How to revert back to the original template??
Type LIBNAME as a command -> this will tell you about the physical location of your SASUSER directory.
Go to that directory in the windows explorer and delete the file "templat.sas7bitm".
Important remark: There is a much more elegant way in SAS itself to delete this "templat.sas7bitm" item store but I don't remember how.
Now submit again:
https://go.documentation.sas.com/api/docsets/statug/14.2/content/statug_code_tteex04.htm?locale=nl
and you will see that everything is back to normal (the default template is used). The original Y-axis is back!
More info on
ODS PATH SHOW
More info on
the yaxisopts= for axis layout
Hope this helps,
Koen
Hello,
To avoid the hassle with the SASUSER library and the deletion of your item-store ("templat.sas7bitm") in the Windows Explorer, you can also start your program with these statements:
ODS PATH work.TEMPLATE (UPDATE)
Sasuser.templat(read)
SASHELP.TMPLMST (READ);
That way, templates are saved in your WORK library and the WORK library (a simple directory on OS-level) is automatically killed when you close your SAS session.
Cheers,
Koen
Two more notes:
1. The double @@ in your input statement is doing nothing. Just drop it.
2. If you don't like the offset (the margin or empty space between the first / last tick and the plot border) then no worry. There are also options to control that.
Just ask.
Cheers,
Koen
That is brilliant and worked absolutely perfectly!
Thanks so much for all your effort - it must have taken a really long time to write out.
I do appreciate it greatly and thanks for explaining it all so well.
Regards
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!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.