Help using Base SAS procedures

How to create groups by deciles

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

How to create groups by deciles

  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,


Accepted Solutions
Solution
‎06-26-2015 12:47 PM
Super User
Posts: 19,770

Re: How to create groups by deciles

Posted in reply to Thomas_mp

Look at proc rank - designed for this Smiley Happy

View solution in original post


All Replies
Solution
‎06-26-2015 12:47 PM
Super User
Posts: 19,770

Re: How to create groups by deciles

Posted in reply to Thomas_mp

Look at proc rank - designed for this Smiley Happy

Occasional Contributor
Posts: 14

Re: How to create groups by deciles

Thank you !!!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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