Hello -,
I plotted the following plots using sgplot procedure:
proc sgplot data=sonic7;
series x=sidobs y=avgbis/ group=music;
by sid;
run;
(SEE ATTACHMENT1)
proc sort data=sonic7;
by music sidobs;
run;
proc summary data=sonic7;
by music sidobs;
var avgbis;
output out=mean1 (drop=_:) mean=mean n=n stderr=stderr;
run;
data meanstdREVISED;
set mean1;
yvalue=mean;
high=yvalue + stderr;
low=yvalue - stderr;
*if 2 le visit le 3 then treatment=1;
*else treatment=0;
run;
* have to sort if using block plot! ;
proc sort data=meanstdREVISED;
by sidobs;
run;
proc format ;
value music_userfmt 0='Control' 1='Music';
*value treat 0=' ' 1='Treatment period';
run;
ods graphics / attrpriority=none;
proc sgplot data=meanstdREVISED;
block x=sidobs block=music / valueattrs=(weight=bold size=10)
valuevalign=bottom filltype=alternate
fillattrs=(color=white)
altfillattrs=(color=yellow)
transparency=.8;
scatter x=sidobs y=yvalue / group=music yerrorlower=low yerrorupper=high
markerattrs=(size=12) errorbarattrs=(thickness=3) name='scatter';
styleattrs datasymbols=(circlefilled diamondfilled) datalinepatterns=(solid
shortdash);
series x=sidobs y=yvalue / group=music name='series';
yaxis values=(0 to 1 by .1);
xaxis label='sidobs' values=(0 to 125 by 25);
keylegend 'scatter' 'series' / location=inside down=2;
format music music_userfmt.; *treatment treat. ;
xaxistable n / class=music location=outside colorgroup=music valueattrs=(weight=bold
size=10) labelattrs=(weight=bold size=10) title='Sample size at each sidobs'
titleattrs=(weight=bold size=10);
run;
Adding a WHERE clause to either the PROC SUMMARY or the PROC SGPLOT should do it:
where sidobs in (0, 25, 50, 75, 100, 125);
You might at least try to describe what is wanted that didn't happen.
some actual data in the form of a data step might help.
I wanted to plot the mean value of "avgbis" at 0, 25, 50, 75, 100, 125 in the second plot. The first plot is good.
First of all, I'm not sure why you have the BLOCK plot in this example, so I would remove it for now. The "n" for the AXISTABLE has too many values, which is why the text runs together. I would create a little data step that adds an "n2" variable, and copies the "n" value only when the "sidobs" value is 0, 25, 50, 75, 100, or 125. All other "sidobs" values should set "n2" to missing (.). Use the "n2" variable on the AXISTABLE instead of the "n" variable.
Let us know if you are try to use the BLOCK statement to create another feature in the graph.
Hope this helps!
Dan
Actually once I take out the bloc, I got something, by the means are every where:
proc sgplot data=meanstdREVISED;
scatter x=sidobs y=yvalue / group=music yerrorlower=low yerrorupper=high
markerattrs=(size=12) errorbarattrs=(thickness=3) name='scatter';
styleattrs datasymbols=(circlefilled diamondfilled) datalinepatterns=(solid
shortdash);
series x=sidobs y=yvalue / group=music name='series';
yaxis values=(0 to 70 by 10);
xaxis label='sidobs' values=(0 to 125 by 25);
keylegend 'scatter' 'series' / location=inside down=2;
format music music_userfmt.; *treatment treat. ;
xaxistable / class=music location=outside colorgroup=music valueattrs=(weight=bold
size=10) labelattrs=(weight=bold size=10) title='Sample size at each sidobs'
titleattrs=(weight=bold size=10);
run;
SEE PLOT3
The variables on your BY statement in your PROC SUMMARY are in the wrong order:
by music sidobs;
should be:
by sidobs music;
That's because you are using sidobs as your X var, but music (group) is changing within each X.
Try that and see what you get.
Thank you, it is giving me the means at each point, but I wish to have mean at 0, 25, 50, 75, 100, 125. I do not know how to do.
See attached Improved plot 4
Adding a WHERE clause to either the PROC SUMMARY or the PROC SGPLOT should do it:
where sidobs in (0, 25, 50, 75, 100, 125);
Thank you very much!
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.