Dear all
I have an employee table where they belong to different departments. I need to hike the salaries of employee from dept A, B, and C by 10,20 and 30 % respectively using do loops. Now the question is how do I do it?
Regards
Mohammed Shareef
for say 5 years.
You should probably post a few records of example input data and what the result should look like.
Depending on you data structure there are likely quite different approaches possible.
The SAS System
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7934 MILLER CLERK 7782 23JAN1982:00:00:00 2200.00 . 10
7782 CLARK MANAGER 7839 09JUN1981:00:00:00 3350.00 . 10
7839 KING PRESIDENT . 17NOV1981:00:00:00 6000.00 . 10
7902 FORD ANALYST 7566 03DEC1981:00:00:00 4650.00 . 20
7788 SCOTT ANALYST 7566 19APR1987:00:00:00 4400.00 . 20
7876 ADAMS CLERK 7788 23MAY1987:00:00:00 2275.00 . 20
7369 SMITH CLERK 7902 17DEC1980:00:00:00 1900.00 . 20
7566 JONES MANAGER 7839 02APR1981:00:00:00 4618.75 . 20
7900 JAMES CLERK 7698 03DEC1981:00:00:00 1587.50 . 30
7698 BLAKE MANAGER 7839 . 3962.50 . 30
7499 ALLEN SALESMAN 7698 20FEB1981:00:00:00 2400.00 300.00 30
7844 TURNER SALESMAN 7698 08SEP1981:00:00:00 2275.00 0.00 30
7521 WARD SALESMAN 7698 22FEB1981:00:00:00 1962.50 500.00 30
7654 MARTIN SALESMAN 7698 28SEP1981:00:00:00 1962.50 1400.00 30
I need a new variable called newsal which should be created using do loop for 3 years with 10,20 and 30 % for dept 10,20 and 30respectively.
Thanks
I have created newsal for 3 years using do loop
(newsal1 = sal * 1.1; newsal2 = newsal1*1.1; newsal3 = newsal2 * 1.1;)
Here is the code...
data want;
set have;
array newsal(3) newsal1-newsal3;
do i=1 to 3 by 1;
select (deptno);
when (10)
do;
if i=1 then newsal(i) = sal * 1.1;
else newsal(i) = newsal(i-1) * 1.1;
end;
when (20)
do;
if i=1 then newsal(i) = sal * 1.2;
else newsal(i) = newsal(i-1) * 1.2;
end;
when (30)
do;
if i=1 then newsal(i) = sal * 1.3;
else newsal(i) = newsal(i-1) * 1.3;
end;
otherwise put 'wrong deptno';
end;
end;
You can simplify your code by simply adding sal to the array:
data want (drop=i);
set have;
array newsal{4} sal newsal1-newsal3;
do i=2 to 4;
newsal{i}=newsal{i-1} * (1.0 + (deptno / 100));
end;
run;
Yeah, Its so nice......
Thank you ..
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.