FOCUS AREAS

Graphics

Sankey Diagram for Path Analytics
Base SAS: ODS Graphics Procedure: SGPLOT

%let gpath='.';
%let dpi=100;

ods html close;
ods listing gpath=&gpath image_dpi=&dpi;

data sankey;
  input id x y thickness y2 y3 xl xh llabel $46-48 hlabel $50-52;
  datalines;
1  0.1  0.8    1   .      .    .     .                
1  0.1  0.8    1   .      .    .     .                
1  0.2  0.8    1   .      .    .     .                
1  0.3  0.4    1   .      .    .     .                
1  0.4  0.4    1   .      .    .     .                
1  0.5  0.4    1   .      .    .     .                
1  0.5  0.4    1   .      .    .     .                
1  0.7  0.4    1   .      .    .     .                

2  0.1  0.2    5   .      .    .     .                
2  0.2  0.2    5   .      .    .     .                
2  0.3  0.535  5   .      .    .     .                
2  0.45 0.535  5   .      .    .     .                
2  0.5  0.535  5   .      .    .     .                
2  0.7  0.535  5   .      .    .     .                

3  0.1  0.55   1   .      .    .     .                
3  0.2  0.55   1   .      .    .     .                
3  0.3  0.67   1   .      .    .     .                
3  0.4  0.67   1   .      .    .     .                
3  0.5  0.67   1   .      .    .     .                
3  0.9  0.67   1   .      .    .     .               

1   .   .      .   0.8    .    0.1   0.12         3
1   .   .      .   0.4    .    0.35  0.37    3    
1   .   .      .   0.4    .    0.38  0.40         3
1   .   .      .   0.4    .    0.62  0.64    3    
1   .   .      .   0.4    .    0.65  0.67         3

2   .   .      .   .    0.2    0.1   0.12         18
2   .   .      .   .    0.535  0.35  0.37    18   
2   .   .      .   .    0.535  0.38  0.40         18
2   .   .      .   .    0.535  0.62  0.64    18   
2   .   .      .   .    0.535  0.65  0.67         18

3   .   .      .   0.55   .    0.1   0.12         3
3   .   .      .   0.67   .    0.35  0.37    3    
3   .   .      .   0.67   .    0.38  0.40         3
3   .   .      .   0.67   .    0.62  0.64    3    
3   .   .      .   0.67   .    0.65  0.67         3
3   .   .      .   0.67   .    0.88  0.90    3    
;
run;

data sankey2;
  length label $10;
  retain del 0.02;
  set sankey end=last;
  output;
  if last then do;
    /*--Labels--*/
    xlbl=0.1; ylbl=0.8+del; label='Index'; output;
	xlbl=0.1; ylbl=0.55+del; label='Item'; output;
	xlbl=0.35; ylbl=0.66+2*del; label='Item'; output;
	xlbl=0.62; ylbl=0.66+2*del; label='Item'; output;
	xlbl=0.85; ylbl=0.66+2*del; label='Checkout'; output;
	xlbl=0.1 ; ylbl=0.2+0.11; label='Search'; output;

	/*--Annoation--*/
	xa=0.05; ya=0.83; anno='1'; output;
	xa=0.77; ya=0.77; anno='2'; output;
	xa=0.77; ya=0.5;  anno='3'; output;

	/*--Lines--*/
	lid=1; xln=0.085; yln=0.75; output;
    lid=1; xln=0.08;  yln=0.75; output;
	lid=1; xln=0.08;  yln=0.83; output;
	lid=1; xln=0.075; yln=0.83; output;
	lid=1; xln=0.08;  yln=0.83; output;
	lid=1; xln=0.08;  yln=0.90; output;
	lid=1; xln=0.085; yln=0.90; output;

	lid=2; xln=0.71; yln=0.71; output;
    lid=2; xln=0.71; yln=0.72; output;
	lid=2; xln=0.77; yln=0.72; output;
	lid=2; xln=0.77; yln=0.73; output;
	lid=2; xln=0.77; yln=0.72; output;
	lid=2; xln=0.82; yln=0.72; output;
	lid=2; xln=0.82; yln=0.71; output;

	lid=3; xln=0.7; yln=0.5; output;
	lid=3; xln=0.75;  yln=0.5;  output;
  end;
run;

ods graphics / reset noborder attrpriority=color width=5in height=3.75in imagename='Sankey';
title "Sankey Diagram for Path Analytics";
footnote j=l "This graph uses the SAS 9.40M3 Spline statement";
proc sgplot data=sankey2 noborder noautolegend nocycleattrs;
  styleattrs datacontrastcolors=(darkred cx5f9f1f blue)
             datacolors=(darkred cx5f9f1f blue);
  spline x=x y=y / group=id thickresp=thickness  thickmax=74 transparency=0.8;
  highlow y=y2 low=xl high=xh / highlabel=hlabel lowlabel=llabel type=bar 
          intervalbarwidth=16 group=id transparency=0.3 nooutline 
          labelattrs=(color=black size=10 weight=bold);
  highlow y=y3 low=xl high=xh / highlabel=hlabel lowlabel=llabel type=bar 
          intervalbarwidth=74 group=id transparency=0.3 nooutline
          labelattrs=(color=black size=10 weight=bold);
  text x=xlbl y=ylbl text=label / position=topright textattrs=(size=10 weight=bold);
  series x=xln y=yln / group=lid nomissinggroup lineattrs=(color=black);
  scatter x=xa y=ya / datalabel=anno datalabelpos=center 
          markerattrs=(symbol=circlefilled color=lightblue size=18) 
          datalabelattrs=(size=12 weight=bold);
  xaxis min=0 max=1 offsetmin=0 offsetmax=0.05 display=none;
  yaxis min=0 max=1 offsetmin=0 offsetmax=0 display=none;
run;

title;
footnote;