hello,
I am trying to show two lines for each group in the group= statement of an sgplot. One line would be the actual value and the other would be the 12 month moving average. I want the actual to be a solid line and the moving average to be a dashed line but I also want the colors to be the same for each item in the group.
I thought that I could exclude the color from the lineattrs so that the defaults would just be used for each of the series but it's not working the way I had hoped. I've tried a lot of the suggestions online but still not working. Originally I want to do this with two by variables (drug and prodname) but that was making it more complicated. I ended up wrapping the plot in a macro and calling out each drug and product name to plot separately.
The following is an hypothetical example with a drug called 'abcdrug' and prodname is blank. Is there a simple statement I can add or ods graphics option I can use without creating numerous lines of code? I often want to do these sorts of graphs on the fly and sometimes not worth creating all the code for it.
%macro shareplot(dname=, prod=) ;
proc sgplot data=share (where = (drug="&dname." and prodname="&prod.")) ;
title "Shares Over Time";
title2 "&dname., &prod." ;
series y=share x= month/ group=strength lineattrs=(thickness=2 pattern=solid) legendlabel="Share by Month" ;
series y=share_12 x= month/ group=strength lineattrs=(thickness=2 pattern=longdash) legendlabel="Share by Month - 12 month MA" ;
YAXIS LABEL = 'Share (%)' ;
YAXIS min=0 max=1 ;
FOOTNOTE " ";
where MONTH>='01JAN2013'd ;
run;
%mend plot ;
%shareplot(dname=abcdrug);
Have you looked at DATA ATTRIBUTE Maps? That's likely what you're after.
https://blogs.sas.com/content/iml/2017/01/30/auto-discrete-attr-map.html
thanks for your response. I spent time using the suggestions in the link but I still cannot get the colors to be in sync between the actual and moving average.
Post your code so we can see and work off what you've already done please.
Without seeing what you've already done, it's pretty hard to make any suggestions here.
@CP2 wrote:
I suppose i can add 'lineattrs' in the map instead of marketstyleelement and hardcode in the colors. I'll try this. Let me know if you have other suggestions related to data attribute maps.
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!
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.