BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jacob_klimek
Obsidian | Level 7

Hi,

 

I am trying to create buckets (bins) based off of the deciles of a variable. I.e I want the first 10% to receive a 1, the 10-20% to receive a 2, etc.

 

Below is an example of what my data looks like:

 

ID      Var

1         2

2         25

3         12

4         16

5         8

6         13

7         9

8         11

9          3

10        1

 

And I want:

 

ID      Var         Bucket

1         2               2

2         25             10

3         12             7

4         16             9

5         8               4

6         13             8

7         9               5

8         11             6

9          3              3

10        1              1

 

I have been trying to work through the syntax using proc rank because I think that's what I want but I just can't get it. I think I am getting frustrated too easily because when I do a similar procedure in Stata it is pretty simple to grasp.

 

Any help would be great, thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

The basic bit is going to look like this:

proc rank data=have out=want groups=10;
   var var;
   ranks bucket;
run;

However proc rank assigns 0 to the lowest rank so you get 0 to 9 as provided in the documentation.

 

So you put your output data set through a data step to add 1;

 

data want; 

   set want;

   bucket = bucket+1;

run;

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Just to add an example of surveyselect:

data have;
  do id=1 to 10;
    var=4;
    output;
  end;
run;
  
proc surveyselect data=have groups=10 seed=49201 out=RandomGroups noprint;
run;
ballardw
Super User

The basic bit is going to look like this:

proc rank data=have out=want groups=10;
   var var;
   ranks bucket;
run;

However proc rank assigns 0 to the lowest rank so you get 0 to 9 as provided in the documentation.

 

So you put your output data set through a data step to add 1;

 

data want; 

   set want;

   bucket = bucket+1;

run;

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 11480 views
  • 4 likes
  • 3 in conversation