When I am looking at this Graph:
I think whether I can get it by PROC SGPLOT ?
Yes. After working with PROC SGPLOT two hours, I got this picture.
data have;
set sashelp.heart(obs=1000);
keep bp_status status sex;
run;
proc freq data=have noprint;
table status/out=freq1 list;
table status*sex/out=freq2 list;
table status*sex*bp_status/out=freq3 list;
run;
%macro circular_plot(dataset_in=,id=);
data temp;
set &dataset_in.;
id+1;id=1000*&id.+id;
pi=PERCENT*0.01*2*constant('pi');
cum_pi+pi;
lag_cum_pi=lag(cum_pi);
if _n_=1 then lag_cum_pi=0;
run;
data plot;
set temp;
/*for a Polygon*/
do _pi=lag_cum_pi to cum_pi by 0.001;
x=&id.*cos(_pi);y=&id.*sin(_pi);output;
end;
x=&id.*cos(_pi);y=&id.*sin(_pi);output;
do _pi=cum_pi to lag_cum_pi by -0.001;
x=%eval(&id.+1)*cos(_pi);y=%eval(&id.+1)*sin(_pi);output;
end;
x=%eval(&id.+1)*cos(_pi);y=%eval(&id.+1)*sin(_pi);output;
keep x y id ;
run;
%CENTROID (plot, sgplot, id)
data want;
merge plot sgplot(rename=(x=centroid_x y=centroid_y)) temp(keep=id count) ;
by id;
output;
call missing(of _all_);
run;
proc append base=final_want data=want force;run;
%mend;
proc delete data=final_want;run;
%circular_plot(dataset_in=freq1,id=1)
%circular_plot(dataset_in=freq2,id=2)
%circular_plot(dataset_in=freq3,id=3)
/*
data temp;
x2=0;y2=1.5;label='Alive or Death';output;
x2=0;y2=2.5;label='Sex';output;
x2=0;y2=3.5;label='Blood Pressure';output;
run;
data final_want2;
set final_want temp;
run;
*/
ods graphics/ANTIALIASMAX=1000000 ;
proc sgplot data=final_want aspect=1 noautolegend noborder;
polygon x=x y=y id=id/fill outline lineattrs=(color=white thickness=2) group=id;
scatter x=centroid_x y=centroid_y/markerchar=count markercharattrs=(size=10) labelstrip;
/*scatter x=x2 y=y2/markerchar=label markercharattrs=(size=14 color=white weight=bold) labelstrip;*/
xaxis offsetmin=0 offsetmax=0 display=none;
yaxis offsetmin=0 offsetmax=0 display=none;
run;
This is a nice effort! I am not a fan of circular plots, but if I ever want to use one, I will definitely use this code as a starting point. Well done!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.