title '1.2 Categorical Data as a Summary Table'; * Create corresponding numeric version variable and format; * Expects detail level for bean counting; proc format; value prodv 1 = 'Boot' 2 = 'Sandal' 3 = 'Slipper' 4 = 'Sport Shoe'; run; data shoes; set sashelp.shoes; if product = 'Boot' then prodv = 1; else if product = 'Sandal' then prodv = 2; else if product = 'Slipper' then prodv = 3; else if product = 'Sport Shoe' then prodv = 4; run; proc report data=shoes nowindows nocenter missing headline headskip nofs list split='*'; * Where condition excludes missing region and prodv values; where region in ('Africa' 'Asia') and product in ('Boot' 'Sandal' 'Slipper'); * AFRICA ASIA; * Boot Sandal Slipper Boot Sandal Slipper; * _c1_ _c2_ _c3_ _c4_ _c5_ _c6_ _c7_ _c8_ _c9_ _c10_ _c11_ _c12_ ; * # % # % # % # % # % # %; column ( region, ( prodv, (prodv = prodvn prodvpct) )); define region /across; define prodv /across "__ Product __" format=prodv.; define prodvn /analysis n format= 3. 'N'; define prodvpct /computed format=percent5. '(%)'; * Code for four responses - sum all products within each region; * totg# for each region option - totg1 is for Africa and totg2 is for Asia; * add totg# if needed for missing regions; * one _c#_ for each prodv value; * add _c#_ if needed for missing prodv; compute before; totg1 = sum(_c1_, _c3_, _c5_); totg2 = sum(_c7_, _c9_, _c11_); endcomp; * Divide each part with total; * _c#_ for each option within product; * add _c#_ statement if needed for missing prodv; compute prodvpct; _c2_ = _c1_ / totg1; _c4_ = _c3_ / totg1; _c6_ = _c5_ / totg1; _c8_ = _c7_ / totg2; _c10_ = _c9_ / totg2; _c12_ = _c11_ / totg2; endcomp; run;