BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
desireatem
Pyrite | Level 9

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)

 

Nex I want to plot the average at time point 0, 25, 50 etc and below is the code. (THE PLOTS DOES NOT COME THE WAY I WANT IT, see ATTACHMENT2)

 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;

               

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

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);

View solution in original post

8 REPLIES 8
ballardw
Super User

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.

desireatem
Pyrite | Level 9

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.

DanH_sas
SAS Super FREQ

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

desireatem
Pyrite | Level 9

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

DanH_sas
SAS Super FREQ

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.

 

 

desireatem
Pyrite | Level 9

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

DanH_sas
SAS Super FREQ

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);

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 8 replies
  • 2102 views
  • 1 like
  • 3 in conversation