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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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