/*******************************************/ /* BLOG 2: Mosaic plots by using PROC FREQ */ /* Rick Wicklin: Blog post 10/4/2013 */ /* http://blogs.sas.com/content/iml/2013/11/04/create-mosaic-plots-in-sas-by-using-proc-freq */ /*******************************************/ proc format; value WtFmt 1 = 'Underweight' 2 = 'Normal' 3 = 'Overweight'; value SmFmt 1 = 'Non-smoker' 2 = 'Light (1-5)' 3 = 'Moderate (6-15)' 4 = 'Heavy (16-25)' 5 = 'Very Heavy (> 25)'; value BPFmt 1 = 'Optimal' 2 = 'Normal' 3 = 'High'; run; data Heart / view=Heart; format Smoking_Cat SmFmt. Weight_Cat WtFmt. BP_Cat BPFmt.; set sashelp.heart; select (Weight_Status); when ('Underweight') Weight_Cat=1; when ('Normal') Weight_Cat=2; when ('Overweight') Weight_Cat=3; when (' ') Weight_Cat=.; end; select (Smoking_Status); when ('Non-smoker') Smoking_Cat=1; when ('Light (1-5)') Smoking_Cat=2; when ('Moderate (6-15)') Smoking_Cat=3; when ('Heavy (16-25)') Smoking_Cat=4; when ('Very Heavy (> 25)') Smoking_Cat=5; when (' ') Smoking_Cat=.; end; select (BP_Status); when ('Optimal') BP_Cat=1; when ('Normal') BP_Cat=2; when ('High') BP_Cat=3; when (' ') BP_Cat=.; end; run; /* colors automatically assigned */ ods graphics on; proc freq data=heart; tables BP_Cat*Weight_Cat / norow chisq plots=MOSAIC; run;