Reference: https://blogs.sas.com/content/iml/2012/10/17/specify-the-colors-of-groups-in-sas-statistical-graphics.html; https://blogs.sas.com/content/graphicallyspeaking/2012/02/27/roses-are-red-violets-are-blue/
Original code use gplot
%macro plots; %do i = 0 %to 1; %if &i=0 %then %do; title height=12pt "Regular Salary Group"; %end; %else %do; title height=12pt "High Salary Group"; %end; %do j = 2 %to 4; %if &j=2 %then %do; title2 height=14pt "&curr_fiscal_year Assistant Professors"; %end; %else %if &j=3 %then %do; title2 height=14pt "&curr_fiscal_year Associate Professors"; %end; %else %do; title2 height=14pt "&curr_fiscal_year Full Professors"; %end; proc gplot data=anno_&i(where=(rank_cd=&j)) anno=anno_&i(where=(rank_cd=&j)); plot y*x / haxis=axis1 vaxis=axis2 noframe; symbol1 v=dot h=.6 w=.6 color='Black'; format basesal comma7.; run; quit; %end; %end; %mend plots; %plots;
New code with the following improvements:
- produce regression line with color and transparency attributes
- produce 95% confidence limit with color and transparency attributes
- produce scatter plot by gender group and use grouporder attribute to make sure fixed color is assigned to Male and Female.
- output the plots to pdf
ods pdf file="X:regression_with_gender_label.pdf"; goptions reset = global; %macro plots; %do i = 0 %to 1; %if &i=0 %then %do; title height=12pt "Regular Salary Group"; %end; %else %do; title height=12pt "High Salary Group"; %end; %do j = 2 %to 4; %if &j=2 %then %do; title2 height=14pt "&curr_fiscal_year Assistant Professors"; %end; %else %if &j=3 %then %do; title2 height=14pt "&curr_fiscal_year Associate Professors"; %end; %else %do; title2 height=14pt "&curr_fiscal_yearFull Professors "; %end; proc sgplot data=log_glm (where=(rank_cd=&j. and area = "&i.")) ; scatter x=exper y=log_sal / group=gender grouporder=ascending name='plot' markerattrs=(symbol=circlefilled); series x=exper y=yhat / name='predict' legendlabel='ln(Predicted Log Sal)' lineattrs=(color=blue ) transparency = 0.5 ; series x=exper y=ucl / name='upper' legendlabel='Upper Confidence Level' lineattrs=(color = lightblue) transparency = 0.5; series x=exper y=lcl / name='lower' legendlabel='Lower Confidence Level' lineattrs=(color = lightblue) transparency = 0.5; run; quit; %end; %end; %mend plots; %plots Ods pdf close;
Problem: myattrmap not reconginzed by the scatter statement though ‘attrid= myid’ doesn’t generate error.
data myattrmap; retain id value linecolor fillcolor; length linecolor $ 9 fillcolor $ 9; input ID $ value $ linecolor $ fillcolor $; datalines; myid F blue blue myid M red red; run;