%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 $ Xn Yn; datalines; 1 John M 1 4 2 Zoe F 0 3 3 Ted M 2 3 4 Philip M 3 4 5 Steve M 1 2 6 Bill M 3 2 7 Mary F 4 1 8 Jane F 2 1 9 Paul M 1 0 ; run; /*--Create Node Hash Table--*/ data _null_; length NodeId Xn Yn 8; 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'); 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 ; run; /*ods html;*/ /*proc print data=nodes;*/ /* var nodeid sex xn yn;run;*/ /*proc print data=links;*/ /* var linkid from to respA;run;*/ /*ods html close;*/ /*--Create Link end-coordinates data--*/ data links2; keep LinkId From To Xl Yl RespA; length NodeId Xn Yn 8; 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'); 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; /*ods html;*/ /*proc print;run;*/ /*ods html close;*/ /*--Create Network--*/ ods graphics / reset width=3in height=3.25in imagename='Network_Nodes' attrpriority=none noborder; title 'Social Network'; proc sgplot data=network noautolegend aspect=1; styleattrs backcolor=cxfaf3f0; scatter x=xn y=yn / group=sex markerattrs=(symbol=circlefilled size=16) filledoutlinedmarkers markerfillattrs=(color=white) markeroutlineattrs=(thickness=4) dataskin=sheen datalabel=name datalabelpos=bottom; xaxis min=0 max=4 display=none; yaxis min=0 max=4 display=none; run; /*--Create Network--*/ ods graphics / reset width=3in height=3.25in imagename='Network_Straight' attrpriority=none noborder; title 'Social Network'; proc sgplot data=network noautolegend aspect=1; styleattrs backcolor=cxfaf3f0; series x=xl y=yl / group=LinkId lineattrs=graphdatadefault; scatter x=xn y=yn / group=sex markerattrs=(symbol=circlefilled size=16) filledoutlinedmarkers markerfillattrs=(color=white) markeroutlineattrs=(thickness=4) dataskin=sheen datalabel=name datalabelpos=bottom; xaxis min=0 max=4 display=none; yaxis min=0 max=4 display=none; run; /*--Compute middle node for curved links--*/ data links3; retain x1 y1; set links2; by linkid; if first.linkid then do; x1=xl; y1=yl; output; 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; xl=xm - 0.15*l*cy; yl=ym + 0.15*l*cx; output; call missing (xm, ym); xl=x2; yl=y2; output; end; run; /*ods html;*/ /*proc print;run;*/ /*ods html close;*/ data Network2; set Nodes Links3; run; /*ods html;*/ /*proc print;run;*/ /*ods html close;*/ /*--Create Network--*/ ods graphics / reset width=3in height=3.25in imagename='Network_Angle' attrpriority=none noborder; title 'Social Network'; proc sgplot data=network2 noautolegend aspect=1; styleattrs datacolors=(blue pink) backcolor=cxfaf3f0; series x=xl y=yl / group=LinkId lineattrs=graphdatadefault; scatter x=xn y=yn / group=sex markerattrs=(symbol=circlefilled size=16) filledoutlinedmarkers markerfillattrs=(color=white) markeroutlineattrs=(thickness=2) dataskin=sheen datalabel=name datalabelpos=bottom; xaxis min=0 max=4 display=none; yaxis min=0 max=4 display=none; run; /*--Create Network--*/ ods graphics / reset width=3in height=3.25in imagename='Network_Curved' attrpriority=none noborder; title 'Social Network'; proc sgplot data=network2 noautolegend aspect=1; styleattrs datacolors=(blue pink) backcolor=cxfaf3f0; spline x=xl y=yl / group=LinkId lineattrs=graphdatadefault; scatter x=xn y=yn / group=sex markerattrs=(symbol=circlefilled size=16) filledoutlinedmarkers markerfillattrs=(color=white) markeroutlineattrs=(thickness=2) dataskin=sheen datalabel=name datalabelpos=bottom; xaxis min=0 max=4 display=none; yaxis min=0 max=4 display=none; run; /*--Create Network--*/ ods graphics / reset width=3in height=3.25in imagename='Network_Curved_Resp' attrpriority=none noborder; title 'Social Network'; proc sgplot data=network2 noautolegend aspect=1; styleattrs datacolors=(blue pink) backcolor=cxfaf3f0; spline x=xl y=yl / group=LinkId lineattrs=graphdatadefault thickresp=respA thickmaxresp=10 thickmax=4; scatter x=xn y=yn / group=sex markerattrs=(symbol=circlefilled size=16) filledoutlinedmarkers markerfillattrs=(color=white) markeroutlineattrs=(thickness=2) dataskin=sheen datalabel=name datalabelpos=bottom; xaxis min=0 max=4 display=none; yaxis min=0 max=4 display=none; run;