BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ChuanC
Calcite | Level 5

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;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

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

4 REPLIES 4
DanH_sas
SAS Super FREQ

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

DanH_sas
SAS Super FREQ

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;
ChuanC
Calcite | Level 5

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

DanH_sas
SAS Super FREQ

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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