Turn on suggestions

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

Showing results for

- Home
- /
- Programming
- /
- Programming
- /
- quartiles for categorical variable

Options

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 07-18-2018 01:24 PM
(1841 views)

Is there a way to divide the categorical into 4 quartiles?

For example I have gender with values F and M and I need to divide all F in 4 quartiles and all M in 4 quartiles.

I know for numeric we can use proc rank but what is the equivalent for categorical?

Thanks

5 REPLIES 5

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@sfo wrote:

Is there a way to divide the categorical into 4 quartiles?

For example I have gender with values F and M and I need to divide all F in 4 quartiles and all M in 4 quartiles.

I know for numeric we can use proc rank but what is the equivalent for categorical?

Thanks

I think you need to provide some example data and what you want the output to look like given that example data. You are using "quartile" in a non-standard way so a more specific example will be helpful.

Do you mean to assign the data into 4 groups fore each sex that are roughly the same size? Does the assignment have to be random? If so perhaps:

Proc sort data=have;

by sex;

run;

Proc surveyselect data=have out=want groups=4;

strata sex;

run;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks for the solution.

Does it work on 9.2?

I am getting an error:

436 Proc surveyselect data=fdaada_popPK out=want groups=4;

------

22

ERROR 22-322: Syntax error, expecting one of the following: ;, (, CERTAIN, CERTSIZE, DATA, JTPROBS, M, MAXSIZE, METHOD,

MINSIZE, N, NMAX, NMIN, NOPRINT, OUT, OUTALL, OUTHITS, OUTSEED, OUTSIZE, OUTSORT, RATE, REPS, SAMPRATE, SAMPSIZE,

SEED, SELECTALL, SORT, SRSALG, STATS.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@sfo wrote:

Thanks for the solution.

Does it work on 9.2?

I am getting an error:

436 Proc surveyselect data=fdaada_popPK out=want groups=4;

------

22

ERROR 22-322: Syntax error, expecting one of the following: ;, (, CERTAIN, CERTSIZE, DATA, JTPROBS, M, MAXSIZE, METHOD,

MINSIZE, N, NMAX, NMIN, NOPRINT, OUT, OUTALL, OUTHITS, OUTSEED, OUTSIZE, OUTSORT, RATE, REPS, SAMPRATE, SAMPSIZE,

SEED, SELECTALL, SORT, SRSALG, STATS.

No, the Groups=option was added in 9.3 (I think).

If Randomness is not an issue this is another way:

Using a SAS set you should have as a starting point:

proc sort data=sashelp.class out=work.class; by sex; run; data work.want; set work.class; by sex; group= mod(_n_,4)+1; run;

Which will evenly distribute the group identifier within the BY variable.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@ballardw wrote:

If Randomness is not an issue this is another way:

Using a SAS set you should have as a starting point:

proc sort data=sashelp.class out=work.class; by sex; run; data work.want; set work.class; by sex; group= mod(_n_,4)+1; run;Which will evenly distribute the group identifier within the BY variable.

And if randomness is an issue, then you can assign random numbers to each observation and use those to split the data into 4 groups.

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@sfo wrote:

For example I have gender with values F and M and I need to divide all F in 4 quartiles and all M in 4 quartiles.

Using what criteria would you do this dividing into quartiles? Explain please! Give an example.

--

Paige Miller

Paige Miller

**Available on demand!**

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

How to Concatenate Values

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.