how do I use if then else statement while exporting data using file statement

Reply
Occasional Contributor
Posts: 14

how do I use if then else statement while exporting data using file statement

The SAS System

this is file from which i have to export data to text file in the format given below this

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

*INFORMATION ABOUT DEPT : 10

~~~~~~~~~~~~~~~~~~~~~~

ENAME JOB SAL DEPTNO

MILLER CLERK 2200.00 10

CLARK MANAGER 3350.00 10

KING PRESIDENT 6000.00 10

INFORMATION ABOUT DEPT : 20

~~~~~~~~~~~~~~~~~~~~~~

ENAME JOB SAL DEPTNO

FORD ANALYST 4650.00 20

SCOTT ANALYST 4400.00 20

ADAMS CLERK 2275.00 20

SMITH CLERK 1900.00 20

JONES MANAGER 4618.75 20

INFORMATION ABOUT DEPT : 30

~~~~~~~~~~~~~~~~~~~~~~

ENAME JOB SAL DEPTNO

JAMES CLERK 1587.50 30

BLAKE MANAGER 3962.50 30

ALLEN SALESMAN 2400.00 30

TURNER SALESMAN 2275.00 30

WARD SALESMAN 1962.50 30

MARTIN SALESMAN 1962.50 30;

Thanks for your help.

Respected Advisor
Posts: 3,156

Re: how do I use if then else statement while exporting data using file statement

something along the line of following code may get you started:

data have;

     input (EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO) (:$30.);

     cards;

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

;

filename txt "c:\temp\dept.txt";

data _null_;

     file txt;

     do _n_=1 by 1 until (last.deptno);

           set have;

           by deptno notsorted;

           if _n_=1 then

                put "INFORMATION ABOUT DEPT :" deptno /"~~~~~~~~~~~~~~~~~~~~~~~~~" /"EMPNO ENAME JOB SAL DEPTNO";

           put EMPNO ENAME JOB SAL DEPTNO;

     end;

     put;

run;


Have a good weekend,

Haikuo

Ask a Question
Discussion stats
  • 1 reply
  • 183 views
  • 0 likes
  • 2 in conversation