%let gpath='.';
%let dpi=200;
ods html close;
ods listing gpath=&gpath image_dpi=&dpi;
/*--Create data for the infographic chart--*/
data Nodes;
length filename $100 Name $10;
input NodeId Name $ Sex $ Group $21-40 Xn Yn;
filename=cat('', Group);
filename=cat (trim(filename), '_Tr.png');
call symput ("File"|| put(_n_, 1.), trim(filename));
datalines;
1 John M Boy_Blue 1 4
2 Zoe F Girl_GreenSmall 0 3
3 Ted M Boy_YellowCap 2 3
4 Philip M Boy_DarkBlue 3 4
5 Steve M Boy_Magenta 1 2
6 Bill M Boy_Red 3 2
7 Mary F Girl_Green 4 1
8 Jane F Girl_Purple 2 1
9 Paul M Boy_RedCap 1 0
;
run;
/*--Create Node Hash Table--*/
data _null_;
length NodeId Xn Yn 8;
length Group $20;
set Nodes end=last;
/* Declare the hash object for Nodes and Links */
if _n_ = 1 then do;
declare hash nodes( ordered:'a');
rc = nodes.defineKey('NodeId');
rc = nodes.defineData('NodeId', 'Xn', 'Yn', 'Group');
rc = nodes.defineDone();
end;
/*--If node is not already in the table, add it.--*/
rc=nodes.find();
if rc ne 0 then do;
nodes.add();
end;
/*--Save Node and Link hash tables--*/
if last then do;
rc = nodes.output(dataset: "work.NetworkNodes");
end;
run;
ods html;
proc print data=work.NetworkNodes;run;
ods html close;
/*--Create data for the infographic chart--*/
data Links;
input LinkId From To RespA;
Xl=.; Yl=.;
datalines;
1 1 2 1
2 1 3 1
3 3 2 1
4 3 4 1
5 3 5 1
6 3 6 8
7 6 8 1
8 6 7 1
9 8 9 1
10 6 3 2
;
run;
/*--Create Link end-coordinates data--*/
data links2;
keep LinkId From To Xl Yl RespA;
length NodeId Xn Yn 8;
length Group $20;
set links end=last;
/* Declare the hash object for Nodes from data set */
if _n_ = 1 then do;
declare hash nodes( dataset:'work.NetworkNodes', ordered:'a');
rc = nodes.defineKey('NodeId');
rc = nodes.defineData('NodeId', 'Xn', 'Yn', 'Group');
rc = nodes.defineDone();
end;
/*--Set "From" node location--*/
NodeId=From;
rc=nodes.find();
if rc eq 0 then do;
xl=xn; yl=yn; output;
end;
/*--Set "To" node location--*/
NodeId=To;
rc=nodes.find();
if rc eq 0 then do;
xl=xn; yl=yn; output;
end;
run;
ods html;
proc print data=links2;run;
ods html close;
data Network;
set Nodes Links2;
run;
/*--Bend of the curve in %--*/
%let off=15;
/*--Compute middle node for curved links--*/
data links3;
drop x1 y1 x2 y2 x3 y3 l dx dy xm ym;
retain x1 y1;
set links2;
by linkid;
if first.linkid then do;
x1=xl; y1=yl;
end;
else do;
/*--Compute and write middle point--*/
x2=xl; y2=yl;
dx=x2-x1; dy=y2-y1; l=sqrt(dx*dx+dy*dy); cx=dx/l; cy=dy/l;
xm=(x1+x2)/2; ym=(y1+y2)/2;
x3=xm - (&off/100)*l*cy; y3=ym + (&off/100)*l*cx;
/*--Write all three vertices with and without shift--*/
fs=0.3;
xl=x1; yl=y1;
/*--Compute direction cosines to the midpoint--*/
dxm=x3-x1; dym=y3-y1;lm=sqrt(dxm*dxm+dym*dym); cxm=dxm/lm;cym=dym/lm;
xls=x1+cxm*lm*fs; yls=y1+cym*lm*fs; Mid=0; output;
xl=x3; yl=y3; xls=x3; yls=y3; Mid=1; output;
xl=x2; yl=y2;
/*--Compute direction cosines to the midpoint--*/
dxm=x3-x2; dym=y3-y2;lm=sqrt(dxm*dxm+dym*dym); cxm=dxm/lm;cym=dym/lm;
xls=x2+cxm*lm*fs; yls=y2+cym*lm*fs; Mid=0; output;
end;
run;
/*ods html;*/
/*proc print;run;*/
/*ods html close;*/
data Network2;
set Nodes Links3;
run;
/*--Create Network with Icons and single links--*/
ods graphics / reset width=3in height=3.25in imagename="Network_Icon_Single_.&off"
attrpriority=none noborder;
title "Social Network (Bend=&off)";
proc sgplot data=network2(where=(linkid ne 10)) noautolegend aspect=1;
symbolimage name=Group1 image="&file1";
symbolimage name=Group2 image="&file2";
symbolimage name=Group3 image="&file3";
symbolimage name=Group4 image="&file4";
symbolimage name=Group5 image="&file5";
symbolimage name=Group6 image="&file6";
symbolimage name=Group7 image="&file7";
symbolimage name=Group8 image="&file8";
symbolimage name=Group9 image="&file9";
styleattrs datasymbols=(group1 group2 group3 group4 group5
group6 group7 group8 group9) backcolor=cxfaf3f0;
spline x=xls y=yls / group=LinkId lineattrs=graphdatadefault arrowheadpos=end
arrowheadshape=filled arrowheadscale=0.5;
scatter x=xn y=yn / group=group markerattrs=(size=40)
dataskin=sheen datalabel=name datalabelpos=bottom;
xaxis min=0 max=4 display=none offsetmin=0.1 offsetmax=0.1;
yaxis min=0 max=4 display=none offsetmin=0.15 offsetmax=0.15;
run;
/*--Create Network with Icons and double links--*/
ods graphics / reset width=3in height=3.25in imagename="Network_Icon_Double_&off"
attrpriority=none noborder;
title "Social Network (Bend=&off)";
proc sgplot data=network2 noautolegend aspect=1;
symbolimage name=Group1 image="&file1";
symbolimage name=Group2 image="&file2";
symbolimage name=Group3 image="&file3";
symbolimage name=Group4 image="&file4";
symbolimage name=Group5 image="&file5";
symbolimage name=Group6 image="&file6";
symbolimage name=Group7 image="&file7";
symbolimage name=Group8 image="&file8";
symbolimage name=Group9 image="&file9";
styleattrs datasymbols=(group1 group2 group3 group4 group5
group6 group7 group8 group9) backcolor=cxfaf3f0;
spline x=xls y=yls / group=LinkId lineattrs=graphdatadefault arrowheadpos=end
arrowheadshape=filled arrowheadscale=0.5;
scatter x=xn y=yn / group=group markerattrs=(size=40)
dataskin=sheen datalabel=name datalabelpos=bottom;
xaxis min=0 max=4 display=none offsetmin=0.1 offsetmax=0.1;
yaxis min=0 max=4 display=none offsetmin=0.15 offsetmax=0.15;
run;