Data visualization with SAS programming

How to assign colors and format in an ODS graph at the same time?

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

How to assign colors and format in an ODS graph at the same time?

Hi all,

 

I need to assign colors to the group/class in a series plot and an axis table, and a superscript is needed for one of class values. Please see the inserted SAS code. 

 

1. I defined a format sup_eth to change "Other1" to "Other" with a superscript 1.

2. The format sup_eth is assigned to a variable "group" in the data UGRD_Div1.

3. UGRD_Div1 is sorted.

4. I defined a template for following SGRender. The template contains two plots, a series plot and an axis table. I use a statement discreteattrvar to identify which part of attribute map to use (attrmap="Eth") on which variable (var=group).

5. A SGRender to output the graph.

 

The variable group in the data UGRD_Div1 has five values, which are Hispanic, Black/African American, Asian, Two or more races and Other1. The colors in the first four values are fine, but the color for Other1 is not the color I want to assign, and the color is actually the ContrastColor for GraphData5 (the default color for the fifth line of a ODS graph in style HtmlBlue). 

 

The color for Other1 is correctly assigned, if I take off the format step. So my conclusion is the format procedure conflicts with the attribute map.

 

My question is how to assign colors and format at the same time in an ODS graph. My specific program is assign a color to a value of a group variable and one value of the variable needs a superscript 1.

 

Thanks for your time to help me in advance!

Chuan

proc format;
  value $sup_eth 
  'Other1' = "Other(*ESC*){unicode '00b9'x}";
run;

Data UGRD_Div1;
  set UGRD_Eth;

  Pct = round (Pct_row,0.1)/100;

  Label_descr = strip(round(Pct_row,0.1))||'% ('||strip(Count)||')';

  format Pct percentn7.1;

  format group $sup_eth.;

run;

Proc sort data=UGRD_Div1;
  by year descending Pct_row ;
run;

Proc template;
  define statgraph UGRD_DIV1;

  begingraph /designwidth=600px designheight=540px ;

  entrytitle 'Percent of Total Undergraduate Enrollment';

  discreteattrvar attrvar=group var=group attrmap="Eth";

  layout lattice/rows=2 rowgutter=0 rowweights=(0.65 0.35);

  layout overlay/xaxisopts=(display=(tickvalues) )
					yaxisopts=(griddisplay=on label='Percent Total Enrollment' /*labelposition=top*/ labelattrs=(weight=bold)) ;
	seriesplot x=year y=Pct /group=group markerattrs=(symbol=circlefilled size=6pt) lineattrs=(thickness=3 ) display=all ;
  endlayout;

  layout overlay /xaxisopts=(type=discrete display=none) border=false ;
    axistable x=year value=Label_descr/class=group colorgroup=group display=(label) ValueATTRS=(color= black) labelattrs=(weight=bold) ;
  endlayout;

  endlayout;
  
  entryfootnote halign=left {sup "1"}" Other includes Alaska Native or American Indian, Native Hawaiian or Other Pacific Islander."/TEXTATTRS=(size=7pt) ;

  endgraph;
  end;
run;

ods rtf file='I:\UGRD_04052018_test.rtf' style=HTMLBLUE ;
proc sgrender data=UGRD_DIV1 template=UGRD_DIV1 DATTRMAP=ATTRMAP;
run;
ods rtf close;

 

 


Accepted Solutions
Solution
‎04-06-2018 01:51 PM
SAS Super FREQ
Posts: 1,047

Re: How to assign colors and format in an ODS graph at the same time?

I looked into this further, and found that there is currently an issue when using inline escapements with attrmap data sets in GTL (works fine for template-based attrmaps). However, data set attrmaps with escapements work fine in the SG procedures (SGPLOT, for example). You're example seems to translate well to SGPLOT. Please try the code below and see if it works for you.

 

Hope this helps!
Dan

 

ods graphics / width=600px height=540px ;
title 'Percent of Total Undergraduate Enrollment';
footnote j=l h=7pt "(*ESC*){sup "1"} Other includes Alaska Native or American Indian, Native Hawaiian or Other Pacific Islander.";

proc sgplot data=UGRD_DIV1 dattrmap=ATTRMAP;
  xaxis  display=(nolabel noline);
  yaxis grid label='Percent Total Enrollment' labelattrs=(weight=bold);
  seriesplot x=year y=Pct / group=group  attrid=Eth markers markerattrs=(symbol=circlefilled size=6pt) lineattrs=(thickness=3);
  xaxistable Label_descr / class=group colorgroup=group label valueattrs=(color= black) labelattrs=(weight=bold);
run;

View solution in original post


All Replies
SAS Super FREQ
Posts: 1,047

Re: How to assign colors and format in an ODS graph at the same time?

How are you defining the Other^1 in your attrmap data set?

Solution
‎04-06-2018 01:51 PM
SAS Super FREQ
Posts: 1,047

Re: How to assign colors and format in an ODS graph at the same time?

I looked into this further, and found that there is currently an issue when using inline escapements with attrmap data sets in GTL (works fine for template-based attrmaps). However, data set attrmaps with escapements work fine in the SG procedures (SGPLOT, for example). You're example seems to translate well to SGPLOT. Please try the code below and see if it works for you.

 

Hope this helps!
Dan

 

ods graphics / width=600px height=540px ;
title 'Percent of Total Undergraduate Enrollment';
footnote j=l h=7pt "(*ESC*){sup "1"} Other includes Alaska Native or American Indian, Native Hawaiian or Other Pacific Islander.";

proc sgplot data=UGRD_DIV1 dattrmap=ATTRMAP;
  xaxis  display=(nolabel noline);
  yaxis grid label='Percent Total Enrollment' labelattrs=(weight=bold);
  seriesplot x=year y=Pct / group=group  attrid=Eth markers markerattrs=(symbol=circlefilled size=6pt) lineattrs=(thickness=3);
  xaxistable Label_descr / class=group colorgroup=group label valueattrs=(color= black) labelattrs=(weight=bold);
run;
New Contributor
Posts: 2

Re: How to assign colors and format in an ODS graph at the same time?

Dan,

 

Thanks very much for your information and help!

 

To your first reply, I include two rows for Other1, and they are

idvaluelinecolormarkercolortextcolor
EthOther1brobrobro
EthOther(*ESC*){unicode '00b9'x}brobrobro

 

I have tried your suggested code. It works very well, except I need to add attrid=Eth at the end of xaxistable, probably because I have multiple items in the attribute map data set.

 

Thanks,

Chuan

SAS Super FREQ
Posts: 1,047

Re: How to assign colors and format in an ODS graph at the same time?

Yes, sorry I missed that. You are using GROUP for both the series group and the axis table colorgroup, so you would want those to be colored the same. For the SG procedures, the ATTRID is required for any plot statement that wants to use the attrmap. If it is left off, the attrmap is not used for that statement.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 136 views
  • 0 likes
  • 2 in conversation