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)
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?
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?
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.
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!
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.
@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
Thanks! I will give it a try on Monday
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;
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.