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.
thanks in advance.
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;
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;
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;
Thanks a lot xia keshan sir
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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.