Hello,
I have a very complicated figure that I'm trying to add a data attribute map to. It works fine when adding it into GTL template code directly, but when making a data attribute map dataset and assigning it in the SGRENDER statement I get the following error:
There is only one attribute ID in the map and I can't figure out what the issue is. I can assign this data attribute map to SGPLOT but the error happens in SGRENDER.
Any ideas what would cause this error? I can't find documentation on it.
It seems that the issue is caused by referring to a variable named VALUE in my dataset within the template. When I changed this variable name the error went away. I'm assuming this is related to VALUE being a required column in the attribute map dataset.
You're missing the DATTRVAR statement on the SGRENDER procedure. You have to use that to bind the attribute map to the correct variable. For example, if you were plotting SASHELP.CLASS with a group variable of SEX, using an attributes map with an ID of "MYID", the SGRENDER would look something like the following:
proc sgrender data=sashelp.class template=mytemplate dattrmap=attrmap;
dattrvar sex="MYID";
run;
Let me know if that works for you. Thanks!
No, the idea was that you can use the attrmap dataset with any GTL template without modifying the template. Your GTL template should have no discrete attribute map syntax. The gives you the ability to use your template with or without the attributes map.
This documentation is what I was following that said I could go either with the DATTRS option or the DISCRETEATTRVAR option: GTL reference
Either way, I removed the attribute map references from my GTL code and tried with the DATTRVAR instead and it resulted in the same error.
I removed my LEGENDITEM statements as well just in case there was something there. I didn't see any other statements with a NAME assignment option either, so I'm pretty lost on what's causing this.
My dataset is just coordinates and an ID column basically for plotting. My GTL code is:
proc template;
%if &nby=1 or %qupcase(&by_method)=PANELS %then %do;
define statgraph _sunburst;
begingraph /
designheight=&GraphHeight.in designwidth=&GraphWidth.in
backgroundcolor=&bg_color
/**Turns the border around the plot off if border=0**/
%if %superq(border)=0 %then %do;
border=false
%end;
subpixel=on;
/*%do i = 1 %to %sysfunc(countw(%superq(_group_lvls),|));
%local fillcolor&i;
%let fillcolor&i=%scan(%superq(colors),&i,%str( ));
legenditem type=fill name="grp&i" / label="%scan(%superq(_group_lvls),&i,|,m)"
fillattrs=(%if %sysevalf(%superq(fillcolor&i)^=,boolean) %then %do;
color=&&fillcolor&i
%end;
%else %if %sysfunc(mod(&i,12))=0 %then %do;
color=graphdata12:color
%end;
%else %do;
color=graphdata%sysevalf(%sysfunc(mod(&i,12))):color
%end;);
%end;
/* discreteattrmap name="attrs" / ignorecase=false;
%do i = 1 %to %sysfunc(countw(%superq(_group_lvls),|));
value "&i" /
fillattrs=(%if %sysevalf(%superq(fillcolor&i)^=,boolean) %then %do;
color=&&fillcolor&i
%end;
%else %if %sysfunc(mod(&i,12))=0 %then %do;
color=graphdata12:color
%end;
%else %do;
color=graphdata%sysevalf(%sysfunc(mod(&i,12))):color
%end;);
%end;
enddiscreteattrmap;
/* discreteattrvar attrvar=_attrs_ var=group_lvl attrmap="attrs" ;*/
/* discreteattrvar attrvar=_attrs_ var=group_lvl attrmap="attrs" ; */
layout lattice / rows=&rows columns=&columns order=columnmajor opaque=false columngutter=5 rowgutter=5;
sidebar / align=&Legend_Location ;
discretelegend
%do i = 1 %to %sysfunc(countw(%superq(_group_lvls),|));
"grp&i"
%end; / title="&group_label" border=false location=outside autoalign=(bottom) opaque=false
valueattrs=(size=&legend_font_size color=&font_color /*family="&font_family"*/)
titleattrs=(size=&legend_font_size color=&font_color /*family="&font_family"*/) exclude=('')
%if %qupcase(&Legend_Location)=RIGHT %then %do; across=1 %end;;
endsidebar;
*entry ' ';
%do b = 1 %to &nby;
%if %sysevalf(%superq(by)^=,boolean) %then %do;
cell;
cellheader;
entry halign=center "%scan(%superq(_by_lvls),&b,|,m)" / valign=bottom
textattrs=(size=&by_font_size color=&font_color weight=&by_font_weight/*family="&font_family"*/);
endcellheader;
%end;
layout overlay / border=false opaque=false walldisplay=none aspectratio=1
xaxisopts=(type=linear display=none
linearopts=(viewmin=&x_viewmin viewmax=&x_viewmax
tickvaluefitpolicy=none) offsetmin=0.03 offsetmax=0.03)
yaxisopts=(type=linear display=none
linearopts=(viewmin=&&y_viewmin&b viewmax=&&y_viewmax&b
minorticks=true minorgrid=true minorgridattrs=(pattern=1 color=greyef))
reverse=false);
/**sunburst Polygons**/
polygonplot x=eval(ifn(_bylvl_=&b,x,.)) y=y id=r_id / display=(fill ) group=group_lvl;
%if &box_outline=1 %then %do;
seriesplot x=eval(ifn(_bylvl_=&b and ^missing(r_id),x,.)) y=y /group=r_id
lineattrs=(%if %sysevalf(%qupcase(&box_outline_color)^=GROUP,boolean) %then %do; color=&box_outline_color %end;
pattern=solid
thickness=&box_outline_size) ;
%end;
/**Text Plot**/
%if &box_show_counts=1 %then %do;
textplot x=eval(ifn(_bylvl_=&b,x_text,.)) y=y_text text=value / position=center splitjustify=center strip=true
%if &rotate_text=1 %then %do; rotate=rotate %end;
textattrs=(size=&count_font_size color=&font_color weight=&count_font_weight /*family="&font_family"*/);
%end;
endlayout;
%if %sysevalf(%superq(by)^=,boolean) %then %do;
endcell;
%end;
%end;
endlayout;
endgraph;
end;
%end;
Too add more information it seems when I remove the TEXTPLOT from my GTL code the error goes away, so there is some kind of interaction going on there that I'm not seeing. I don't even have a group variable in my TEXTPLOT.
It seems that the issue is caused by referring to a variable named VALUE in my dataset within the template. When I changed this variable name the error went away. I'm assuming this is related to VALUE being a required column in the attribute map dataset.
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.