I am currently having a nightmare with some kernel density plots I am trying to produce. For some reason in the plots where I am plotting two kernel density lines, despite showing correctly in the SAS output window, the RTF file I am creating show both lines as the same colour. I do not have the same issue in the plots with 3 or more kernel density plots overlaid. These are showing fine as different colours in both the SAS output window and the output RTF file.
Code below:
proc sgplot data=graph CYCLEATTRS;
%do r=1 %to &n;
density &endpoint&r / type=kernel freq=frequency name="&r" legendlabel="&&class&r (n=&&count&r)" lineattrs=(pattern=solid thickness=2);
%end;
keylegend /
valueattrs=(Size=7);
yaxis label='Density';
run;
Any help would be greatly appreciated!
Yes, what you report is true. It has to do with the RTF style being different than modern styles such as the HTML styles. What happens is
There are two workaround. You could delete the PATTERN=SOLID option, but I am assuming you don't want to do this. The second workaround is to modify your macro loop to explicitly use the GRAPHDATA family of attributes, like this:
proc sgplot data=graph CYCLEATTRS;
%do r=1 %to &n;
density &endpoint&r / type=kernel freq=frequency name="&r" legendlabel="&&class&r (n=&&count&r)"
lineattrs=GraphData&r.(pattern=solid thickness=2);
%end;
keylegend /
valueattrs=(Size=7);
yaxis label='Density';
run;
Hello @SamR and welcome to the SAS Support Communities!
This is interesting. I have reproduced the issue and found a difference in the GTL (Graph Template Language) code created by adding the TMPLOUT= option to the PROC SGPLOT statement: With only two density curves the corresponding DensityPlot statements use the following LINEATTRS= options:
Lineattrs=GraphFit( Pattern=1 Thickness=2) Lineattrs=GraphFit2( Pattern=1 Thickness=2)
By adding a third density curve the GraphFit style elements are replaced by GraphData style elements:
Lineattrs=GraphData1( Pattern=1 Thickness=2) Lineattrs=GraphData2( Pattern=1 Thickness=2) Lineattrs=GraphData3( Pattern=1 Thickness=2)
Which makes sense because there are about 15 GraphData style elements, but only two GraphFit style elements. Apparently, GraphData work better with your line pattern and thickness specifications.
So I suggest that you enforce the use of GraphData by adding that to your existing LINEATTRS= option of the DENSITY statement:
... lineattrs=GraphData&r(pattern=solid thickness=2);
Does this work in your environment?
@FreelanceReinh is absolutely correct. For the RTF style used by ODS RTF by default, the GraphFit and GraphFit2 colors are the same color -- differentiable only by the line pattern and thickness. When you overrode those attributes, the lines looked the same.
You have two options:
1) Use a different ODS style. The available styles will vary based on your SAS version.
2) Change your macro to set GraphDataN ("N" replaced by your loop index) on each of your density plots. For example, iineattrs=GraphData1(pattern=solid thickness=2)
Hope this helps!
Yes, what you report is true. It has to do with the RTF style being different than modern styles such as the HTML styles. What happens is
There are two workaround. You could delete the PATTERN=SOLID option, but I am assuming you don't want to do this. The second workaround is to modify your macro loop to explicitly use the GRAPHDATA family of attributes, like this:
proc sgplot data=graph CYCLEATTRS;
%do r=1 %to &n;
density &endpoint&r / type=kernel freq=frequency name="&r" legendlabel="&&class&r (n=&&count&r)"
lineattrs=GraphData&r.(pattern=solid thickness=2);
%end;
keylegend /
valueattrs=(Size=7);
yaxis label='Density';
run;
Thank you so much for the responses. Added in lineattrs=GraphData&r. works!
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.