BookmarkSubscribeRSS Feed
Calcite | Level 5


 Hello All, 


My Sgplot code looks like below and the Legend that appearing "Name = a " ( Treatment arms )  at the end of Vbox . Along with that I also want the Scatter Plot colors in the Legend , if I try to have Name = "Scat"  and use it in Keylegend TRT01A is coming up as it is Grouping variable . How to get the Scatter Plot color into the Legend ?


Example  along with TRT arm ,  red color = &var2. , Green color = &var1 something like this 


%macro box_j (yvar , var1,var2 , out , Vis , label  );

     /*--Grouped Box with Stat Table Scatter--*/;


ods graphics / reset attrpriority=color width=5in height=3in imagename= "&out._&vis._Box_jitter" ;

Title "Boxplot ";


proc sgplot data=mergedGroup ;

label value='N';   format value 5.2;

yaxis values = (-6 to 6 by 2);

vbox &yvar. / category= &var2. group=TRT01A nooutliers  nofill grouporder=ascending name='a';


scatter x=&var2. y=&yvar.   / group=TRT01A groupdisplay=cluster

        grouporder=ascending jitter

        markerattrs=(symbol=circlefilled size=5  color = red  )

        transparency=0.5 clusterwidth=0.5  *Name = "Scat" * ; <-- I want  &var2 color in the Legend 


scatter x=&var1.  y=&yvar.  / group=TRT01A groupdisplay=cluster

      grouporder=ascending jitter

      markerattrs=(symbol=square size=5   color = green )

      transparency=0.65 clusterwidth=1; <-- I want  &var1 color in the Legend 


xaxistable STD / x=cat class=grp classdisplay=cluster colorgroup=grp location=inside classorder=ascending label = "&var2.";

xaxis display=(nolabel);

keylegend 'a' / linelength=24;

*keylegend 'Scat' / linelength=24;




%MEND box_j;



%box_j(lV4 , TRT,FR , log  , V4 ,%str( V4 ) );



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg



Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 0 replies
  • 1 in conversation