I'm trying to plot an average transition/mean and SD chart with sgplot+limitstat.
Elapsed time for the x-axis, use the variable VISITN.
The visit numbers are 0 6 7. (Baseline, Week 6, Week 7)
The time intervals on the x-axis are evenly spaced.
It is as if you are displaying Baseline Week1 Week2.
What should I do to reflect the actual time as shown in the figure?
Please help me.
== What I try/search ==
We CAN NOT do this with limitstat?
There was a sample that went through 1 data step and used scatter, yerrorlower, yerrorupper instead of limitstat.
https://www.sas.com/content/dam/SAS/ja_jp/doc/event/sas-user-groups/usergroups11-b-19.pdf
(About Sample program, I also Thank to this site.)
data TEST;
ID =1;TREAT ="Placebo";GENDER ="Male";CAT =3;Visit ="Baseline";Visitn =0;VAL =54.9;output;
ID =1;TREAT ="Placebo";GENDER ="Male";CAT =3;Visit ="Week 6";Visitn =6;VAL =52.4;output;
ID =1;TREAT ="Placebo";GENDER ="Male";CAT =3;Visit ="Week 7";Visitn =7;VAL =62.9;output;
ID =2;TREAT ="TAK-XXX XXmg";GENDER ="Female";CAT =3;Visit ="Baseline";Visitn =0;VAL =56.9;output;
ID =2;TREAT ="TAK-XXX XXmg";GENDER ="Female";CAT =3;Visit ="Week 6";Visitn =6;VAL =47.4;output;
ID =2;TREAT ="TAK-XXX XXmg";GENDER ="Female";CAT =3;Visit ="Week 7";Visitn =7;VAL =69.9;output;
ID =3;TREAT ="TAK-XXX XXmg";GENDER ="Male";CAT =1;Visit ="Baseline";Visitn =0;VAL =64.9;output;
ID =3;TREAT ="TAK-XXX XXmg";GENDER ="Male";CAT =1;Visit ="Week 6";Visitn =6;VAL =55.8;output;
ID =3;TREAT ="TAK-XXX XXmg";GENDER ="Male";CAT =1;Visit ="Week 7";Visitn =7;VAL =46.7;output;
ID =4;TREAT ="TAK-XXX XXmg";GENDER ="Male";CAT =2;Visit ="Baseline";Visitn =0;VAL =54.5;output;
ID =4;TREAT ="TAK-XXX XXmg";GENDER ="Male";CAT =2;Visit ="Week 6";Visitn =6;VAL =47.9;output;
ID =4;TREAT ="TAK-XXX XXmg";GENDER ="Male";CAT =2;Visit ="Week 7";Visitn =7;VAL =59.6;output;
ID =5;TREAT ="Placebo";GENDER ="Male";CAT =2;Visit ="Baseline";Visitn =0;VAL =39.6;output;
ID =5;TREAT ="Placebo";GENDER ="Male";CAT =2;Visit ="Week 6";Visitn =6;VAL =56.1;output;
ID =5;TREAT ="Placebo";GENDER ="Male";CAT =2;Visit ="Week 7";Visitn =7;VAL =42.1;output;
ID =6;TREAT ="TAK-XXX XXmg";GENDER ="Female";CAT =1;Visit ="Baseline";Visitn =0;VAL =50.3;output;
ID =6;TREAT ="TAK-XXX XXmg";GENDER ="Female";CAT =1;Visit ="Week 6";Visitn =6;VAL =52.3;output;
ID =6;TREAT ="TAK-XXX XXmg";GENDER ="Female";CAT =1;Visit ="Week 7";Visitn =7;VAL =63.5;output;
run;
proc sgplot data=TEST ;
vline VISIT /
response = VAL
group = TREAT
stat = mean
limitstat = stddev
numstd = 1
markers
markerattrs
= (symbol=circlefilled) ;
run ;
Result
what I want
proc sgplot data=TEST ;
vline VISITn /
response = VAL
group = TREAT
stat = mean
limitstat = stddev
numstd = 1
markers
markerattrs
= (symbol=circlefilled) ;
xaxis offsetmin=0.1 offsetmax=0.1 values=(0 to 7 by 1)
valuesdisplay=('Baseline' ' ' ' ' ' ' ' ' ' ' 'Week 6' 'Week 7');
run ;
proc sgplot data=TEST ;
vline VISITn /
response = VAL
group = TREAT
stat = mean
limitstat = stddev
numstd = 1
markers
markerattrs
= (symbol=circlefilled) ;
xaxis offsetmin=0.1 offsetmax=0.1 values=(0 to 7 by 1)
valuesdisplay=('Baseline' ' ' ' ' ' ' ' ' ' ' 'Week 6' 'Week 7');
run ;
thank you. Even if I change "visit" to "visitn", my code didn't work either.
Looking at your code, the most effect seems to be the description of the Xaxis statement, thanks.
Setting the tick values explicitly does work, but I wanted to make everyone aware of another alternative that might be more flexible if your data changes from run-to-run. The XAXIS for your VLINE chart can be set to be LINEAR, which will cause the numbers to be plotted linearly along the axis, while the plot is calculated discretely. Then, you can just define a user-defined format to turn the numbers into the correct strings. Below is the modification to your code to demonstrate this approach.
proc format;
value timeline
0 = "Baseline"
1 = "Week 1"
2 = "Week 2"
3 = "Week 3"
4 = "Week 4"
5 = "Week 5"
6 = "Week 6"
7 = "Week 7";
run;
proc sgplot data=TEST ;
format visitn timeline.;
xaxis type=linear;
vline VISITn /
response = VAL
group = TREAT
stat = mean
limitstat = stddev
numstd = 1
markers
markerattrs
= (symbol=circlefilled) ;
run ;
Hope this helps!
Dan
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.