BookmarkSubscribeRSS Feed
momin
Calcite | Level 5

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

6 REPLIES 6
momin
Calcite | Level 5

for say 5 years.

ballardw
Super User

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.

momin
Calcite | Level 5

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

RaviKommuri
Fluorite | Level 6

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;                                                

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

RaviKommuri
Fluorite | Level 6

Yeah, Its so nice......

Thank you ..

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 873 views
  • 2 likes
  • 4 in conversation