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
@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;
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.
@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.
@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.
@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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.