BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
hellohere
Pyrite | Level 9

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?

 

SGPlot398.png

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;
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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;

Ksharp_0-1666096519681.png

 

View solution in original post

7 REPLIES 7
hellohere
Pyrite | Level 9
If put as label somewhere in PLOT/Chart, not in title, that is OK also!!!
PeterClemmensen
Tourmaline | Level 20

You want the text in the title to have different coloring, based on some condition, right?

hellohere
Pyrite | Level 9

Yes. Or anywhere in Chart. 

Ksharp
Super User

It looks like a moving average. 

@Rick_SAS  wrote a blog about it.

hellohere
Pyrite | Level 9

Yes, it is MA.

 

Need to color-code the gap, either in title line, or label-alike(anywhere else).

Ksharp
Super User

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;

Ksharp_0-1666096519681.png

 

hellohere
Pyrite | Level 9
Thanks a huge

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 796 views
  • 2 likes
  • 3 in conversation