Help using Base SAS procedures

How to create a variable with n levels based on the size of the data

Accepted Solution Solved
Reply
Contributor
Posts: 52
Accepted Solution

How to create a variable with n levels based on the size of the data

Hi,

To explain what I want, please let me show the simple code:

proc sort data=work.city;

  by descending gdp;

run;

Then I want to create a variable in the data work.city, which indicates the group that the case belongs to based on its gdp level. Group 1 has the largest gdp, and group 10 has the lowest gdp. Each group has equal number of cases.

How can do it?

Cheers.

Ruth.


Accepted Solutions
Solution
‎08-18-2011 02:21 PM
PROC Star
Posts: 7,363

How to create a variable with n levels based on the size of the data

Couldn't you just use proc rank .. the data doesn't even have to be sorted.  Just specify the number of groups you want. e.g.,

data city;

  input city gdp;

  cards;

1 10

2 9

3 8

4 7

5 6

6 5

7 4

8 3

9 2

10 12

11 13

12 14

;

proc rank data=city groups=4 out=want;

  var gdp;

  ranks gdprank;

run;

View solution in original post


All Replies
Solution
‎08-18-2011 02:21 PM
PROC Star
Posts: 7,363

How to create a variable with n levels based on the size of the data

Couldn't you just use proc rank .. the data doesn't even have to be sorted.  Just specify the number of groups you want. e.g.,

data city;

  input city gdp;

  cards;

1 10

2 9

3 8

4 7

5 6

6 5

7 4

8 3

9 2

10 12

11 13

12 14

;

proc rank data=city groups=4 out=want;

  var gdp;

  ranks gdprank;

run;

☑ This topic is SOLVED.

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

Discussion stats
  • 1 reply
  • 78 views
  • 0 likes
  • 2 in conversation