## how to achieve the desired result

Solved
Frequent Contributor
Posts: 111

# how to achieve the desired result

Hi all,

 empid salary 1 15000 2 20000 3 30000 4 45000 5 60000 6 70000 7 10000 8 20000 9 100000 10 35000 11 40000 12 7000 13 90000 14 80000 15 70000 16 65000 17 87000 18 56000 19 8000 20 7000 21 12000 22 19000 23 23000 24 34000 25 46000 26 58000 27 67000 28 78000 29 5000 30 84000

having the data like above.
empid and salary information is available in pdf.
min salary is 5000 and maximum is 100000.
i want the output like devide this salaries into 5 group.
each group contain 20000 salaries. i.e.

sal_group                              count(employees)

1st group 0-20000               number of employees in that each group.
2nd group 20000-40000       number of employees in that each group.
last group
80000-100000                     number of employees in that each group.

Accepted Solutions
Solution
‎02-10-2015 06:44 AM
Super User
Posts: 10,761

## Re: how to achieve the desired result

data have;

input empid salary ;

cards;

1 15000

2 20000

3 30000

4 45000

5 60000

6 70000

7 10000

8 20000

9 100000

10 35000

11 40000

12 7000

13 90000

14 80000

15 70000

16 65000

17 87000

18 56000

19 8000

20 7000

21 12000

22 19000

23 23000

24 34000

25 46000

26 58000

27 67000

28 78000

29 5000

30 84000

;

run;

proc format;

value fmt

0-20000='1'

20000<-40000='2'

40000<-60000='3'

60000<-80000='4'

80000<-100000='5';

run;

data want;

set have;

group=put(salary,fmt.);

run;

All Replies
Super Contributor
Posts: 320

## Re: how to achieve the desired result

I think a simple division of Salary will do the trick. No Proc is needed. You need an array to hold the counts.

data want;

array k[5] _temporary_;

set have end = eof;

i = ceil(salary / 20000);

k + 1;

if eof then

do i = 1 to dim(k);

group = i;

low_value = (i - 1) * 20000;

high_value = i * 20000;

count = k;

output;

end;

keep group low_value high_value count;

run;

Solution
‎02-10-2015 06:44 AM
Super User
Posts: 10,761

## Re: how to achieve the desired result

data have;

input empid salary ;

cards;

1 15000

2 20000

3 30000

4 45000

5 60000

6 70000

7 10000

8 20000

9 100000

10 35000

11 40000

12 7000

13 90000

14 80000

15 70000

16 65000

17 87000

18 56000

19 8000

20 7000

21 12000

22 19000

23 23000

24 34000

25 46000

26 58000

27 67000

28 78000

29 5000

30 84000

;

run;

proc format;

value fmt

0-20000='1'

20000<-40000='2'

40000<-60000='3'

60000<-80000='4'

80000<-100000='5';

run;

data want;

set have;

group=put(salary,fmt.);

run;

Frequent Contributor
Posts: 111

## Re: how to achieve the desired result

Thanks a lot xia keshan sir

Super User
Posts: 10,761

## Re: how to achieve the desired result

data have;

input empid salary ;

cards;

1 15000

2 20000

3 30000

4 45000

5 60000

6 70000

7 10000

8 20000

9 100000

10 35000

11 40000

12 7000

13 90000

14 80000

15 70000

16 65000

17 87000

18 56000

19 8000

20 7000

21 12000

22 19000

23 23000

24 34000

25 46000

26 58000

27 67000

28 78000

29 5000

30 84000

;

run;

proc format;

value fmt

0-20000='1'

20000<-40000='2'

40000<-60000='3'

60000<-80000='4'

80000<-100000='5';

run;

data want;

set have;

group=put(salary,fmt.);

run;

🔒 This topic is solved and locked.

Discussion stats
• 4 replies
• 262 views
• 0 likes
• 3 in conversation