BookmarkSubscribeRSS Feed
Jack1
Obsidian | Level 7

I have the following data on quarterly sales by type (called WAM, SME and FS) by source of change: lost, new and top 10 gainers.  Using PROC GREPLAY I can place all the graphs on 1 slide using this code:

 

data trends;
length type $14.;
infile datalines missover;
input type $ period $ sme_adv fs_adv wam_adv;
datalines;
lost CY17Q1 -490 -39 -2
lost CY17Q2 -478 -38 -3
lost CY17Q3 -505 -78 -2
lost CY17Q4 -491 -44 -43
lost CY18Q1 -491 -44 -1
lost CY18Q2 -485 -46 -10
lost CY18Q3 -460 -181 -13
lost CY18Q4 -442 -387 -12
lost CY19Q1 -407 -468 -21
lost CY19Q2 -433 -178 -5
lost CY19Q3 -447 -181 -5
lost CY19Q4 -421 -298 -2
lost CY20Q1 -395 -286 -3
lost CY20Q2 -410 -259 -19
lost CY20Q3 -411 -359 -25
lost CY20Q4 -537 -427 -10
new CY17Q1 19 206 26
new CY17Q2 428 264 2
new CY17Q3 397 496 1
new CY17Q4 460 888 2
new CY18Q1 492 1047 100
new CY18Q2 531 522 12
new CY18Q3 568 490 50
new CY18Q4 414 810 1
new CY19Q1 427 685 1
new CY19Q2 468 750 8
new CY19Q3 439 687 7
new CY19Q4 581 404 52
new CY20Q1 961 246 97
new CY20Q2 960 130 110
new CY20Q3 1136 246 110
new CY20Q4 831 289 150
top_10_gainers CY17Q1 60 345 1038
top_10_gainers CY17Q2 35 254 1043
top_10_gainers CY17Q3 80 517 579
top_10_gainers CY17Q4 55 436 267
top_10_gainers CY18Q1 110 377 190
top_10_gainers CY18Q2 122 433 993
top_10_gainers CY18Q3 150 521 682
top_10_gainers CY18Q4 100 420 1320
top_10_gainers CY19Q1 90 336 1518
top_10_gainers CY19Q2 75 364 1189
top_10_gainers CY19Q3 50 602 560
top_10_gainers CY19Q4 55 377 1969
top_10_gainers CY20Q1 80 636 3655
top_10_gainers CY20Q2 92 1431 3114
top_10_gainers CY20Q3 111 2359 8896
top_10_gainers CY20Q4 150 1859 4191
;

%macro mylist(name,type,measure);
ODS tagsets.sasreport13(ID=EGSR) gtitle; * Puts the title inside the graph (https://communities.sas.com/t5/SAS-Enterprise-Guide/Locating-titles-inside-of-chart-area-in-proc-sgplot/td-p/229762?nobounce) see Feb 10, 2017 note from SAS;
ods graphics / reset=all imagename=&name. height=3.75in width=6.5in;

title4 FONT='Arial Narrow/Bold' HEIGHT=20 PT COLOR=Black ;
PROC SGPLOT DATA = trends noborder noautolegend nowall noborder pad=0;
where type=&type.;
SERIES X = period Y = &measure. / LINEATTRS = (color=blue THICKNESS = 5);
XAXIS DISPLAY=(NOLABEL) GRID valueattrs=(color=black size=12pt) LABELATTRS=(color=black size=12pt weight=bold) fitpolicy=thin;
YAXIS DISPLAY=(NOLABEL) GRID valueattrs=(color=blue size=12pt weight=bold) LABELATTRS=(color=blue size=12pt weight=bold);
RUN; 
title4;
%mend;
%mylist('sme_adv_lost','lost',sme_adv);
%mylist('sme_adv_new','new',sme_adv);
%mylist('sme_adv_top10_gainers','top_10_gainers',sme_adv);
%mylist('wam_adv_lost','lost',WAM_adv);
%mylist('wam_adv_new','new',WAM_adv);
%mylist('wam_adv_top10_gainers','top_10_gainers',WAM_adv);


******End of data generation********************;
* Create graphical catalogue to place multiple charts on one page;
%macro delcat(catname);

%if %sysfunc(cexist(&catname)) 
%then %do; 
proc greplay nofs igout=&catname; 
delete _all_; 
run;
quit; 
%end; 
%mend delcat; 
%delcat(work.gseg)

* Create graphical catalogue to place multiple charts on one page; 
proc greplay tc=work.tmplt nofs; 
tdef PK1 
1 / llx = 0 lly = 51 ulx = 0 uly = 100 lrx = 33 lry = 51 urx = 33 ury = 100 
2 / llx = 34 lly = 51 ulx = 34 uly = 100 lrx = 66 lry = 51 urx = 66 ury = 100 
3 / llx = 67 lly = 51 ulx = 67 uly = 100 lrx = 100 lry = 51 urx = 100 ury = 100 
4 / llx = 0 lly = 0 ulx = 0 uly = 50 lrx = 33 lry = 0 urx = 33 ury = 50 
5 / llx = 34 lly = 0 ulx = 34 uly = 50 lrx = 66 lry = 0 urx = 66 ury = 50 
6 / llx = 67 lly = 0 ulx = 67 uly = 50 lrx = 100 lry = 0 urx = 100 ury = 50 ;
run; 
quit;

ods _all_ close; 
ods listing; 
options orientation=landscape topmargin=.25IN bottommargin=.25IN 
leftmargin=.25IN rightmargin=.25IN ; 
goptions reset=all device=PNG300 nodisplay hsize=6.5in vsize=3.75in;


%let workdir=%trim(%sysfunc(pathname(work)));
ods listing gpath="&workdir" image_dpi=100;

goptions reset=all device=PNG300 nodisplay vsize=3.75in hsize=6.5in imagestyle=fit;

goptions iback="&workdir.\sme_adv_lost.png"; 
proc gslide name='sgplot1'; run; quit;

goptions iback="&workdir.\sme_adv_new.png"; 
proc gslide name='sgplot2'; run; quit;

goptions iback="&workdir.\sme_adv_top10_gainers.png"; 
proc gslide name='sgplot3'; run; quit;

goptions iback="&workdir.\wam_adv_lost.png"; 
proc gslide name='sgplot4'; run; quit;

goptions iback="&workdir.\wam_adv_new.png"; 
proc gslide name='sgplot5'; run; quit;

goptions iback="&workdir.\wam_adv_top10_gainers.png"; 
proc gslide name='sgplot6'; run; quit;

goptions reset=all device=png300 hsize=8in vsize=5.5in; 
ods _all_ close; 
ODS rtf file='C:\user\SAS_Customer_Data\base_analysis\sales_segment.rtf' image_dpi=300 ; 

* Place first 4 charts onto one page; 
proc greplay igout=work.gseg
tc=work.tmplt nofs; 
template PK1; 
treplay 1:1 2:2 3:3 4:4 5:5 6:6 ; 
run;
quit; 
ods _all_ close; 
ods listing;

Which gives me the following image:

 

greplay_no_titles_no_colors.PNG

 

However I need to enhance this group of graphs with the following:

1. Main title

2. Row and column titles

3. Color each graph using a stop light analogy.  Using the latest reported quarter I want the entire graph to be colored in the following way based on CY20Q4 values vs CY19Q4 values (which are YoY changes):

           if CY20Q4 > CY19Q4 then color = green

           if CY20Q4 < CY19Q4 then color = red

           if CY20Q4 = CY19Q4 then color = yellow

 

So the end graph looks like this:

 

after.PNG

How do I do this?

Thanks.

 

1 REPLY 1
AhmedAl_Attar
Ammonite | Level 13

The techniques in this paper https://www.lexjansen.com/phuse/2006/cc/CC07.pdf

might work for you,

 

Hope this helps,

Ahmed

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1 reply
  • 475 views
  • 0 likes
  • 2 in conversation