turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- univariate

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-05-2013 07:12 AM

how to calculate the mode, frequency of mode and nof distinct categories of all character variables in a dataset.

Prefer proc univariate.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-05-2013 08:15 AM

Supersonic,

You cannot use PROC UNVIARIATE to calculate statistics on categorical variables.

However, PROC FREQ or PROC SQL can give you this information:

proc freq data = sashelp.class;

table sex;

ods output OneWayFreqs = my_count;

run;

*in this case the 'mode' will be sex= M, since it has the highest number of occurrences?

proc sql;

select sex from (select sex, count(1) as count_sex from sashelp.class group

by sex)

having count_sex = max(count_sex);

quit;

....oh,well.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-05-2013 08:51 AM

the above eg will give only thetotal frequency.

i need to calculate the mode, and its frequency and nof distinct categories.

suppose i have a list of variables in a macro list &list

so i need to claculate the mode for all variables in that list.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-05-2013 09:18 AM

ok, it's a bit hard for me to understand the meaning of "mode" for categorical variables. So, what about this:

DATA TEMP;

SET SASHELP.CLASS;

IF NAME = "Janet" THEN NAME = "Jane";

IF NAME = "James" THEN NAME = "Jane";

IF . <AGE < 12 THEN AGE_GRP = "< 12 yrs ";

ELSE IF 12 <= AGE <= 13 THEN AGE_GRP = "12-13 yrs";

ELSE AGE_GRP = "> 13 yrs";

RUN;

PROC FREQ DATA = TEMP;

TABLES SEX AGE_GRP;

ODS OUTPUT ONEWAYFREQS = MY_F(KEEP = F_: FREQUENCY);

RUN;

PROC UNIVARIATE DATA = MY_F;

VAR FREQUENCY;

WHERE F_AGE_GRP NE " ";

RUN;

PROC UNIVARIATE DATA = MY_F;

VAR FREQUENCY;

WHERE F_SEX NE " ";

RUN;

In the first step, I modify the data SASHELP.CLASS to create another categorical variable, age_grp.

Then you run a frequency for the categorical variables...output a data set that will give you nof distinct categories. Then run a univariate on it...and you get the mode (if it exists)...