Data Employee;
Input empno ename$ job$ Mgr hiredate sal comm deptno;
cards;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO 7369 SMITH CLERK 7902 17-Dec-80 800 20 7499 ALLEN SALESMAN 7698 20-Feb-81 1600 300 30 7521 WARD SALESMAN 7698 22-Feb-81 1250 500 30 7566 JONES MANAGER 7839 02-Apr-81 2975 20 7654 MARTIN SALESMAN 7698 28-Sep-81 1250 1400 30 7698 BLAKE MANAGER 7839 01-May-81 2850 30 7782 CLARK MANAGER 7839 09-Jun-81 2450 10 7788 SCOTT ANALYST 7566 19-Apr-87 3000 20 7839 KING PRESIDENT null 17-Nov-81 5000 10 7844 TURNER SALESMAN 7698 08-Sep-81 1500 0 30 7876 ADAMS CLERK 7788 23-May-87 1100 20 7900 JAMES CLERK 7698 03-Dec-81 950 30 7902 FORD ANALYST 7566 03-Dec-81 3000 20 7934 MILLER CLERK 7782 23-Jan-82 1300 10
;
Tried everything but unable to create proper dataset having blank spaces in "comm" variable.
Please help me with the SAS program
Thanks in advance,
Ayushmaan
I think this gives you what you need
Data Employee;
infile cards missover;
Input empno 1-4 ename $ 7-12 job $ 16-24 Mgr 26-29 chardate $ 32-40 sal 43-46 comm 49- 52 deptno 56-57;
format hiredate date9.;
hiredate = input(compress(chardate,'-'),date7.);
cards;
7369   SMITH   CLERK     7902  17-Dec-80  800          20 
7499   ALLEN   SALESMAN  7698  20-Feb-81  1600   300   30 
7521   WARD    SALESMAN  7698  22-Feb-81  1250   500   30 
7566  JONES    MANAGER   7839  02-Apr-81  2975         20 
7654  MARTIN   SALESMAN  7698  28-Sep-81  1250  1400   30 
7698  BLAKE    MANAGER   7839  01-May-81  2850         30
7782  CLARK    MANAGER   7839  09-Jun-81  2450         10 
7788  SCOTT    ANALYST   7566  19-Apr-87  3000         20 
7839  KING     PRESIDENT null  17-Nov-81  5000         10 
7844  TURNER   SALESMAN  7698  08-Sep-81  1500  0      30
7876  ADAMS    CLERK     7788  23-May-87  1100         20 
7900  JAMES    CLERK     7698  03-Dec-81  950          30 
7902  FORD     ANALYST   7566  03-Dec-81  3000         20 
7934  MILLER   CLERK     7782  23-Jan-82  1300         10 
;
run;You need to use column input http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000148066.htm
@ab12nov wrote:
Tried everything but unable to create proper dataset having blank spaces in "comm" variable.
Please help me with the SAS program
If you show what you've tried we can help point out what you need to change instead of doing your assignment.
Hi,
sorry if it looked as if I'm giving you an assignment or so... please find the below code and output dataset.
Data Employee;
infile cards missover;
retain empno ename job Mgr hiredate sal comm deptno;
Input empno ename$ job$ Mgr hiredate sal comm deptno;
hiredate = compress(hiredate,'-');
informat hiredate DATE9.;
cards;
7369 SMITH CLERK 7902 17-Dec-80 800 20 7499 ALLEN SALESMAN 7698 20-Feb-81 1600 300 30 7521 WARD SALESMAN 7698 22-Feb-81 1250 500 30 7566 JONES MANAGER 7839 02-Apr-81 2975 20 7654 MARTIN SALESMAN 7698 28-Sep-81 1250 1400 30 7698 BLAKE MANAGER 7839 01-May-81 2850 30 7782 CLARK MANAGER 7839 09-Jun-81 2450 10 7788 SCOTT ANALYST 7566 19-Apr-87 3000 20 7839 KING PRESIDENT null 17-Nov-81 5000 10 7844 TURNER SALESMAN 7698 08-Sep-81 1500 0 30 7876 ADAMS CLERK 7788 23-May-87 1100 20 7900 JAMES CLERK 7698 03-Dec-81 950 30 7902 FORD ANALYST 7566 03-Dec-81 3000 20 7934 MILLER CLERK 7782 23-Jan-82 1300 10
run;
OUTPUT is in the attachment
Thanks.
I think this gives you what you need
Data Employee;
infile cards missover;
Input empno 1-4 ename $ 7-12 job $ 16-24 Mgr 26-29 chardate $ 32-40 sal 43-46 comm 49- 52 deptno 56-57;
format hiredate date9.;
hiredate = input(compress(chardate,'-'),date7.);
cards;
7369   SMITH   CLERK     7902  17-Dec-80  800          20 
7499   ALLEN   SALESMAN  7698  20-Feb-81  1600   300   30 
7521   WARD    SALESMAN  7698  22-Feb-81  1250   500   30 
7566  JONES    MANAGER   7839  02-Apr-81  2975         20 
7654  MARTIN   SALESMAN  7698  28-Sep-81  1250  1400   30 
7698  BLAKE    MANAGER   7839  01-May-81  2850         30
7782  CLARK    MANAGER   7839  09-Jun-81  2450         10 
7788  SCOTT    ANALYST   7566  19-Apr-87  3000         20 
7839  KING     PRESIDENT null  17-Nov-81  5000         10 
7844  TURNER   SALESMAN  7698  08-Sep-81  1500  0      30
7876  ADAMS    CLERK     7788  23-May-87  1100         20 
7900  JAMES    CLERK     7698  03-Dec-81  950          30 
7902  FORD     ANALYST   7566  03-Dec-81  3000         20 
7934  MILLER   CLERK     7782  23-Jan-82  1300         10 
;
run;On your input statement define the starting column of the comm field like @49 comm 5. .
Thats because it does not have a '.' to show the data is missing
Im not sure exactly what position comm starts in.
also use the options Missing=' '; you might have to define deptno also.
Jim
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.
