DATA Step, Macro, Functions and more

how to create dataset with the data provided.

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 19
Accepted Solution

how to create dataset with the data provided.

[ Edited ]

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


Accepted Solutions
Solution
‎07-23-2017 05:50 PM
Super Contributor
Posts: 441

Re: how to create dataset with the data provided.

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;

View solution in original post


All Replies
Occasional Contributor
Posts: 15

Re: how to create dataset with the data provided.

You can create a excel file with the given data and then import the excel in sas using proc import or ui tools if available.
Occasional Contributor
Posts: 19

Re: how to create dataset with the data provided.

Thanks Bipasha, I know we can do it by importing it through excel but I was being asked to do this with infile cards only.
Super Contributor
Posts: 441

Re: how to create dataset with the data provided.

Occasional Contributor
Posts: 19

Re: how to create dataset with the data provided.

Posted in reply to ChrisBrooks
even if I use column input method. the data is not in a proper indexes as in.

please check line 3rd and 4th for column empno ename$, their indexes are different.
Super User
Posts: 19,862

Re: how to create dataset with the data provided.


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.

 

 

 

Occasional Contributor
Posts: 19

Re: how to create dataset with the data provided.

[ Edited ]

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.


output.jpg
Solution
‎07-23-2017 05:50 PM
Super Contributor
Posts: 441

Re: how to create dataset with the data provided.

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;
Occasional Contributor
Posts: 19

Re: how to create dataset with the data provided.

Posted in reply to ChrisBrooks
thanks a lot budd....!! really helped..
Frequent Contributor
Posts: 95

Re: how to create dataset with the data provided.

[ Edited ]

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

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 324 views
  • 0 likes
  • 5 in conversation