BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
PaigeMiller
Diamond | Level 26

I am trying to perform SG Annotation with BY Variables. In this trivial example, I want one plot with a red arrow for the plot of Male data; and one plot for the females with a green arrow, depending on the value of SEX in SASHELP.CLASS

 

Here's my code that doesn't work (stealing from the example here).

 

%sganno                                       
data sgannodata;  
  set sashelp.class(obs=2);  
  if sex='M' then do;
      %sgarrow(x1=51, x2=30, y1=30, y2=30, linecolor="red")
  end;
  else if sex='F' then do;
       %sgarrow(x1=51, x2=30, y1=30, y2=35, linecolor="green")
  end;
  keep sex; 
run;
proc sort data=sashelp.class out=class;
    by descending sex ;
run;
proc sgplot data=class sganno=sgannodata;     
  scatter x=age y=weight;
  by descending sex;
run;

 

Here's the incorrect output (the correct output would be the red arrow on the males and the green arrow on the females, not both arrows on both plots)

 

PaigeMiller_1-1714751178909.png

 

 

 

 

 

 

--
Paige Miller
1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

Unfortunately, we do not currently support BY-grouping annotation. I would recommend calling Technical Support and have them add a request for this feature. In the meantime, there might be some workarounds to get what you need. Can you elaborate on your specific annotation requirement?

View solution in original post

8 REPLIES 8
DanH_sas
SAS Super FREQ

Unfortunately, we do not currently support BY-grouping annotation. I would recommend calling Technical Support and have them add a request for this feature. In the meantime, there might be some workarounds to get what you need. Can you elaborate on your specific annotation requirement?

PaigeMiller
Diamond | Level 26

Thanks, @DanH_sas 

 

My real problem isn't really that much different from the above, I have two groups, and on each plot I want arrows appropriate for that group based on the data for that group. I can always write a macro loop as the work-around. I will contact Technical Support as you suggested.

--
Paige Miller
DanH_sas
SAS Super FREQ

A better workaround for you would be to use a VECTOR plot. I would create the data for the vector plot in a separate dataset and match-merge that with the original data. Set the GROUP on the vector plot to be the same as the BY-group variable, and then you'll be able to control the arrow attributes from  discrete attrmap.

 

Hope this helps!

PaigeMiller
Diamond | Level 26

I have never used a VECTOR plot, but I looked the documentation at https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/grstatproc/n19gxtzyuf79t3n16g5v26b73ckv.htm#p... and it does not seem like it fits my use case.

 

I want a number of arrows on each plot, they do not all start from the same origin (which seems like VECTOR plots require). The data determines the start point and end point of each arrow on a plot, the start points on each plot do not have to match and the end points on each plot do not have to match.

--
Paige Miller
ballardw
Super User

@PaigeMiller wrote:

I have never used a VECTOR plot, but I looked the documentation at https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/grstatproc/n19gxtzyuf79t3n16g5v26b73ckv.htm#p... and it does not seem like it fits my use case.

 

I want a number of arrows on each plot, they do not all start from the same origin (which seems like VECTOR plots require). The data determines the start point and end point of each arrow on a plot, the start points on each plot do not have to match and the end points on each plot do not have to match.


I think you would be wanting the XORIGIN=variable and YORIGIN=variable to modify the origin of each vector.

So if you can supply an (Xorigin,Yorigin) coordinate for the start and the (X,Y) coordinate for the end of the vector you're golden.

 

There is an example of using these options in a Vector plot at https://support.sas.com/kb/39/078.html

PaigeMiller
Diamond | Level 26

Thanks! I will give it a try on Monday

--
Paige Miller
Ksharp
Super User

Paige,

I think you used wrong tool .

If you want change the color of LINE or MARKERS ... ,you need use DATTRMAP= function.

 

data dattrmap;
input id $ value $ linecolor $ ;
cards;
id F green 
id M red  
;
run;



proc sort data=sashelp.class out=class;
    by descending sex ;
run;
data class;
 set class;
 by descending sex;
 if first.sex and sex='F' then do; x1=51; x2=30; y1=30; y2=35;end;
 if first.sex and sex='M' then do; x1=51; x2=30; y1=30; y2=30;end;
run;
proc sgplot data=class dattrmap=dattrmap;     
  scatter x=age y=weight;
  vector x=x2 y=y2/xorigin=x1 xorigin=y1 group=sex attrid=id;
  by descending sex;
run;

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
  • 542 views
  • 6 likes
  • 4 in conversation