BookmarkSubscribeRSS Feed
sfo
Quartz | Level 8 sfo
Quartz | Level 8

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
ballardw
Super User

@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;

sfo
Quartz | Level 8 sfo
Quartz | Level 8

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.

ballardw
Super User

@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.

 

PaigeMiller
Diamond | Level 26

@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
PaigeMiller
Diamond | Level 26

@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

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 2585 views
  • 2 likes
  • 3 in conversation