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

  Hello,

  I have several variables that I want to group by deciles.  I want to create a new variable that assigns each observation to a decile:
For instance I have two variables Va, and Vb  (id is a variable to identify the observation)  I want to create two other variables Va_decile
and Vb_decile that assigns each observation to a decile.:

An example, the input file is:

DATA groups;

   INPUT id Va  Vb ;

   DATALINES;

1 2 102

2 3.8 99

3 5.9 95.5

4 8.3 91.5

5 9.8 89

6 2.3 101.5

7 10.1 88.5

8 6.2 95

9 4.1 98.5

10 10.7 87.5

11 9.2 90

12 9.5 89.5

13 6.8 94

14 2.6 101

15 2.9 100.5

16 4.4 98

17 8.6 91

18 7.4 93

19 5.3 96.5

20 3.2 100

21 10.4 88

22 8.9 90.5

23 7.1 93.5

24 4.7 97.5

25 3.5 99.5

26 8 92

27 6.5 94.5

28 5.6 96

29 5 97

30 7.7 92.5

The output file should be something like:

id Va    Va_decile  Vb   Vb_decile

1  2       1               102          10

2  3.8    3                99              8

3 5.9 5  95.5 6

4 8.3 8  91.5 3

5 9.8 9  89 2

6 2.3 1  101.5 10

7 10.1 10  88.5 1

8 6.2 5  95 6

9 4.1 3  98.5 8

10 10.7 10  87.5 1

11 9.2 9  90 2

12 9.5 9  89.5 2

13 6.8 6  94 5

14 2.6 1  101 10

15 2.9 2  100.5 9

16 4.4 3  98 8

17 8.6 8  91 3

18 7.4 7  93 4

19 5.3 4  96.5 7

20 3.2 2  100 9

21 10.4 10  88 1

22 8.9 8  90.5 3

23 7.1 6  93.5 5

24 4.7 4  97.5 7

25 3.5 2  99.5 9

26 8 7  92 4

27 6.5 6  94.5 5

28 5.6 5  96 6

29 5 4  97 7

30 7.7 7  92.5 4

Thank you for your help,

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Look at proc rank - designed for this Smiley Happy

View solution in original post

2 REPLIES 2
Reeza
Super User

Look at proc rank - designed for this Smiley Happy

Thomas_mp
Obsidian | Level 7

Thank you !!!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1710 views
  • 0 likes
  • 2 in conversation