BookmarkSubscribeRSS Feed
VioletaB
Calcite | Level 5

Hello,

 

I copied here an answer from previous question see below. However, in this example 3 median for same treatment is plotted at same stop, how to make that Week 12 all 3 treatment would be plotted next to each other (same for week26) to be able to see difference between values? Thanks

data stats;
  input @1 avisit $10. @9 avisitn armn armcd $ median q1 q3;
  datalines;
Baseline  0 60 DummyA 5639 2909 7221.5
Baseline  0 70 DummyB 3876 2929 6587
Baseline  0 80 DummyC 5112 3284 6686
Week1     12 60 DummyA 3304 1961 6157.5
Week12   12 70 DummyB 3496 1717 5021.5
Week12   12 80 DummyC 4266.5 3436 6504.5
Week26   26 60 DummyA 3762 2409 6233
Week26   26 70 DummyB 4377 3380 6735
Week26   26 80 DummyC 4261 3242 6084
;
run;

proc sort data=stats out=sorted; by avisitn armcd; run;

proc sgplot data=sorted noautolegend;
series x=avisitn y=median / markers markerattrs=(symbol=circlefilled size=9) group=armcd curvelabel;
highlow x=avisitn high=q3 low=q1 / lineattrs=(thickness=2) group=armcd;
run;

 

 

7 REPLIES 7
ballardw
Super User

One way is to add a small value to the xaxis variable.

data toplot;
   set sorted;
   by avisitn;
   if first.avisitn then counter=0;
   if avisitn>0 then avisitn=avisitn+counter;
   counter+0.1;  /* if the 0.1 doesn't get the desired space try larger/smaller value*/

run;

proc sgplot data=toplot noautolegend;
series x=avisitn y=median / markers markerattrs=(symbol=circlefilled size=9) group=armcd curvelabel;
highlow x=avisitn high=q3 low=q1 / lineattrs=(thickness=2) group=armcd;

run;

The BY statement in a data step creates automatic variables First. and Last. for each variable on the by statement. These are numeric 1/0 and the 1 is treated as true. So you can test if a value is the first or last and reset or set values. The Counter+0.1; makes the variable Counter retained across iterations of the data step and if not the first of the Avisitn values will be available to make the numeric Avisitn slightly larger for each one in the group. The exception is that the 0 values do not get any increment though could if the "if avisit>0 then" were removed.

Ksharp
Super User
/*You need add another two options:
groupdisplay= and clusterwidth=*/
proc sgplot data=sorted noautolegend;
series x=avisitn y=median / markers markerattrs=(symbol=circlefilled size=9) 
                            group=armcd curvelabel groupdisplay=cluster clusterwidth=0.2;
highlow x=avisitn high=q3 low=q1 / lineattrs=(thickness=2) 
                            group=armcd groupdisplay=cluster clusterwidth=0.2;
run;

Ksharp_0-1673350970322.png

 

VioletaB
Calcite | Level 5

Thanks for this. The issue is still how to add markers and legend .I am using this:

styleattrs Datasymbols=(circleFilled asterisk trianglefilled)
Datalinepatterns=(solid shortdash mediumdashshortdash)
DATACONTRASTCOLORS=(black black black);

 

and add legend, but it does not show the right legend.

ballardw
Super User

Details.

Markers WHERE?

Legend: what should the legend show? You say "does not show the right legend." so what is wrong with the legend you are getting? Without details it is very hard to provide suggestions.

 

Show your entire proc sgplot code.

VioletaB
Calcite | Level 5

So I have 3 groups, datasymbols provide different symbol for each time point,datalinepatterns for lines between symbols.

If I use keylegend/ location=outside position=bottom;

each group have just datalinepatterns, but not datalinepatterns+datasymbol 

ballardw
Super User

Let's try this again: Show the complete Proc SGplot code you are using.

 


@VioletaB wrote:

So I have 3 groups, datasymbols provide different symbol for each time point,datalinepatterns for lines between symbols.

If I use keylegend/ location=outside position=bottom;

each group have just datalinepatterns, but not datalinepatterns+datasymbol 


 

Ksharp
Super User
ods graphics/attrpriority=none;
proc sgplot data=sorted ;
styleattrs Datasymbols=(circleFilled asterisk trianglefilled)
Datalinepatterns=(solid shortdash mediumdashshortdash)
DATACONTRASTCOLORS=(black black black);

series x=avisitn y=median / markers markerattrs=(size=9) name='x'
                            group=armcd curvelabel groupdisplay=cluster clusterwidth=0.2;
highlow x=avisitn high=q3 low=q1 / lineattrs=(thickness=2) 
                            group=armcd groupdisplay=cluster clusterwidth=0.2;

keylegend 'x' / location=outside position=bottom ;
run;

Ksharp_0-1674617074078.png

 

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
  • 7 replies
  • 1048 views
  • 6 likes
  • 3 in conversation