Help using Base SAS procedures

how to achieve the desired result

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 111
Accepted Solution

how to achieve the desired result

Hi all,

empidsalary
115000
220000
330000
445000
560000
670000
710000
820000
9100000
1035000
1140000
127000
1390000
1480000
1570000
1665000
1787000
1856000
198000
207000
2112000
2219000
2323000
2434000
2546000
2658000
2767000
2878000
295000
3084000

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.

thanks in advance.


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

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;

View solution in original post


All Replies
Super Contributor
Posts: 255

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: 9,682

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: 9,682

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.

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

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