I am plotting with SGPLOT and like to have words in diff. COLOR(base on value, if <0 then RED; else BLUE) in title.
That way, dif4 should be RED and dif3 BLUE. How to do it?
29877 proc sql noprint;
29878 select md3y-md4y_ema_e into: dif_3y from &plotds. having ind=max(ind);
NOTE: The query requires remerging summary statistics back with the original data.
29879 select md4y-md4y_ema_e into: dif_4y from &plotds. having ind=max(ind);
NOTE: The query requires remerging summary statistics back with the original data.
29880 quit;
NOTE: PROCEDURE SQL used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
29881 title "&dt. dif4= &dif_4y. dif3=&dif_3y.";
29882 proc sgplot data=&plotds.;
29883 series x=ind y=fut;
29884 series x=ind y=md3y/y2axis lineattrs=(thickness=2 pattern=solid);
29885 series x=ind y=md3y_ema_e/y2axis lineattrs=(color=red thickness=2 pattern=solid);
29886 series x=ind y=md4y/y2axis lineattrs=(thickness=2 pattern=solid);
29887 series x=ind y=md4y_ema_e/y2axis lineattrs=(color=red thickness=1.5 pattern=solid);
29888 run;
29888! quit;
That is easy. How about this one ?
%let dt=1018;
%let dif_4y=-0.14;
%let dif_3y=0.35;
%let dif4=%sysfunc(ifc(&dif_4y.<0,red,blue));
%let dif3=%sysfunc(ifc(&dif_3y.<0,red,blue));
title "&dt. " color=&dif4 "dif4= &dif_4y. " color=&dif3 "dif3=&dif_3y.";
proc sgplot data=sashelp.stocks;
where stock='IBM';
series x=date y=close;
run;
You want the text in the title to have different coloring, based on some condition, right?
Yes. Or anywhere in Chart.
It looks like a moving average.
@Rick_SAS wrote a blog about it.
Yes, it is MA.
Need to color-code the gap, either in title line, or label-alike(anywhere else).
That is easy. How about this one ?
%let dt=1018;
%let dif_4y=-0.14;
%let dif_3y=0.35;
%let dif4=%sysfunc(ifc(&dif_4y.<0,red,blue));
%let dif3=%sysfunc(ifc(&dif_3y.<0,red,blue));
title "&dt. " color=&dif4 "dif4= &dif_4y. " color=&dif3 "dif3=&dif_3y.";
proc sgplot data=sashelp.stocks;
where stock='IBM';
series x=date y=close;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.