Укажите переменную offence_type
в отдельном операторе CLASS
, который использует опцию ORDER=FREQ
.
Пример:
- Первый табличный график показывает порядок классов в порядке возрастания данных,
- Второй табулат показывает эффект
CLASS <var>/ ORDER=FREQ
. - Третий табулат показывает дополнительный эффект
BY <group-vars>
(и некоторые хитрости, чтобы избежать заголовка над каждой BY
группой).
ods listing;
options
pagesize=1000
nodate nonumber nocenter
formdlim=' '
formchar="|----|+|---+=|-/\<>*"
;
dm 'listing; clear';
data have(index=(country));
do country = 'Zeroland ', 'Switzerland', 'Crimeland';
do year = 1980 to year(today());
date = mdy(1,1,year);
do date = date to intnx('year',date,1);
crime = scan ('theft robbery assault parking', min(4,rand('geometric', 0.6)));
/***********************************************\
|* edit, make robbery predominant in Crimeland *|
\***********************************************/
if country = 'Crimeland' then do;
crime = scan ('robbery theft assault parking', min(4,rand('geometric', 0.6)));
end;
output;
end;
end;
end;
format date date9.;
run;
Таблицы
proc tabulate data=have NOSEPS format=8.;
title1 "Tabulate: default class ordering Alphabetical";
*where country like 'S%' and year < 1984;
where year < 1982;
class country year ;
class crime;
tables country, ALL year, crime / condense;
run;
proc tabulate data=have NOSEPS format=8.;
title1 "Tabulate: CLASS / order=freq - crimes Frequency Descending";
title2 "freq ordering based on all data";
* where country like 'S%' and year < 1984;
where year < 1982;
class country year ;
class crime / order=freq;
tables ALL country, ALL year, crime / condense;
run;
data for_tabulate(index=(country));
set have;
title1 = 'NOBYLINE, TITLE in Data. / order=freq by group';
title2 = 'Country ' || country;
run;
options nobyline;
proc tabulate data=for_tabulate NOSEPS format=8.;
title;
* where country like 'S%' and year < 1984;
where year < 1982;
by country;
class title1 title2 year ;
class crime / order=freq;
tables
title1 * title2,
ALL year,
crime
/ condense
;
run;
Вывод списка
Алфавитный
Tabulate: default class ordering Alphabetical
country Crimeland
------------------------------------------------------------
| | crime |
| |-----------------------------------|
| |assault |parking |robbery | theft |
| |--------+--------+--------+--------|
| | N | N | N | N |
|----------------------+--------+--------+--------+--------|
|All | 69| 50| 438| 176|
|year | | | | |
|1980 | 39| 29| 214| 85|
|1981 | 30| 21| 224| 91|
------------------------------------------------------------
country Switzerland
------------------------------------------------------------
| | crime |
| |-----------------------------------|
| |assault |parking |robbery | theft |
| |--------+--------+--------+--------|
| | N | N | N | N |
|----------------------+--------+--------+--------+--------|
|All | 70| 44| 178| 441|
|year | | | | |
|1980 | 42| 27| 84| 214|
|1981 | 28| 17| 94| 227|
------------------------------------------------------------
country Zeroland
------------------------------------------------------------
| | crime |
| |-----------------------------------|
| |assault |parking |robbery | theft |
| |--------+--------+--------+--------|
| | N | N | N | N |
|----------------------+--------+--------+--------+--------|
|All | 74| 38| 189| 432|
|year | | | | |
|1980 | 36| 25| 89| 217|
|1981 | 38| 13| 100| 215|
------------------------------------------------------------
Частота (по всем) по убыванию
Tabulate: CLASS / order=freq - crimes Frequency Descending
freq ordering based on all data
All
------------------------------------------------------------
| | crime |
| |-----------------------------------|
| | theft |robbery |assault |parking |
| |--------+--------+--------+--------|
| | N | N | N | N |
|----------------------+--------+--------+--------+--------|
|All | 1049| 805| 213| 132|
|year | | | | |
|1980 | 516| 387| 117| 81|
|1981 | 533| 418| 96| 51|
------------------------------------------------------------
country Crimeland
------------------------------------------------------------
| | crime |
| |-----------------------------------|
| | theft |robbery |assault |parking |
| |--------+--------+--------+--------|
| | N | N | N | N |
|----------------------+--------+--------+--------+--------|
|All | 176| 438| 69| 50|
|year | | | | |
|1980 | 85| 214| 39| 29|
|1981 | 91| 224| 30| 21|
------------------------------------------------------------
country Switzerland
------------------------------------------------------------
| | crime |
| |-----------------------------------|
| | theft |robbery |assault |parking |
| |--------+--------+--------+--------|
| | N | N | N | N |
|----------------------+--------+--------+--------+--------|
|All | 441| 178| 70| 44|
|year | | | | |
|1980 | 214| 84| 42| 27|
|1981 | 227| 94| 28| 17|
------------------------------------------------------------
country Zeroland
------------------------------------------------------------
| | crime |
| |-----------------------------------|
| | theft |robbery |assault |parking |
| |--------+--------+--------+--------|
| | N | N | N | N |
|----------------------+--------+--------+--------+--------|
|All | 432| 189| 74| 38|
|year | | | | |
|1980 | 217| 89| 36| 25|
|1981 | 215| 100| 38| 13|
------------------------------------------------------------
Частота (по группе BY) по убыванию
title1 NOBYLINE, TITLE in Data. / order=freq by group
and title2 Country Crimeland
------------------------------------------------------------
| | crime |
| |-----------------------------------|
| |robbery | theft |assault |parking |
| |--------+--------+--------+--------|
| | N | N | N | N |
|----------------------+--------+--------+--------+--------|
|All | 438| 176| 69| 50|
|year | | | | |
|1980 | 214| 85| 39| 29|
|1981 | 224| 91| 30| 21|
------------------------------------------------------------
title1 NOBYLINE, TITLE in Data. / order=freq by group
and title2 Country Switzerland
------------------------------------------------------------
| | crime |
| |-----------------------------------|
| | theft |robbery |assault |parking |
| |--------+--------+--------+--------|
| | N | N | N | N |
|----------------------+--------+--------+--------+--------|
|All | 441| 178| 70| 44|
|year | | | | |
|1980 | 214| 84| 42| 27|
|1981 | 227| 94| 28| 17|
------------------------------------------------------------
title1 NOBYLINE, TITLE in Data. / order=freq by group
and title2 Country Zeroland
------------------------------------------------------------
| | crime |
| |-----------------------------------|
| | theft |robbery |assault |parking |
| |--------+--------+--------+--------|
| | N | N | N | N |
|----------------------+--------+--------+--------+--------|
|All | 432| 189| 74| 38|
|year | | | | |
|1980 | 217| 89| 36| 25|
|1981 | 215| 100| 38| 13|
------------------------------------------------------------