BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ab12nov
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisBrooks
Ammonite | Level 13

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

9 REPLIES 9
Bipasha
Obsidian | Level 7
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.
ab12nov
Obsidian | Level 7
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.
ab12nov
Obsidian | Level 7
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.
Reeza
Super User

@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.

 

 

 

ab12nov
Obsidian | Level 7

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
ChrisBrooks
Ammonite | Level 13

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;
ab12nov
Obsidian | Level 7
thanks a lot budd....!! really helped..
Jim_G
Pyrite | Level 9

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 9 replies
  • 1351 views
  • 0 likes
  • 5 in conversation