DATA Step, Macro, Functions and more

Why i am not able to print j1 ?

Reply
Occasional Contributor
Posts: 10

Why i am not able to print j1 ?

dm"log;clear;output;clear";
DATA pumpkins1;
infile datalines dlm="," dsd;
length name $16 ;
input name $ age type $ EnterDate mmddyy10. (j1-j5);
DATALINES;
Alicia Grossman,13,C,10-28-2008,7.8,6.5,7.2,8.0,7.9
Matthew Lee,9,D,10-30-2008,6.5,5.9,6.8,6.0,8.1
Elizabeth Garcia,10,C,10-29-2008,8.9,7.9,8.5,9.0,
,6,D,10-30-2008,6.7,5.6,4.9,5.2,6.1
Jose Martinez,7,D,10-31-2008,8.9,,10.0,9.7,9.0
Brian Williams,11,C,10-29-2008,7.8,8.4,8.5,7.9,8.0
;
RUN;
PROC PRINT data = pumpkins1;
format Enterdate mmddyy10.;
RUN;

 

my output is attached


j1_not_printing.JPG
Super User
Posts: 5,091

Re: Why i am not able to print j1 ?

Because the date variable is read using formatted input (not list input), the input pointer stops before the comma that follows the date.

 

The software starts looking for J1, and then hits the comma so J1 is missing.  (Notice how the remaining variables J2-J5 are reading the values that you actually intended for J1-J4.)

 

An easy fix:  change the INPUT statement to move past that comma:


input name $ age type $ EnterDate mmddyy10. +1 (j1-j5);

 

That's untested code, but should resolve the problem.

Trusted Advisor
Posts: 1,399

Re: Why i am not able to print j1 ?

I cann't explain why but I changed the INFILE statment and the INPUTstatement, until it worked fine:

 

INFILE DATALINES DLM=","  TRUNCOVER;

input name $ age type $ EnterDate mmddyy10. j1-j5;

 

Respected Advisor
Posts: 4,655

Re: Why i am not able to print j1 ?

Should be:

 

DATA pumpkins1;
infile datalines dsd; /* dsd implies dlm="," */
length name $16 ;
input name $ age type $ EnterDate :mmddyy10. j1-j5; /* Check list input in the doc */
DATALINES;
Alicia Grossman,13,C,10-28-2008,7.8,6.5,7.2,8.0,7.9
Matthew Lee,9,D,10-30-2008,6.5,5.9,6.8,6.0,8.1
Elizabeth Garcia,10,C,10-29-2008,8.9,7.9,8.5,9.0,
,6,D,10-30-2008,6.7,5.6,4.9,5.2,6.1
Jose Martinez,7,D,10-31-2008,8.9,,10.0,9.7,9.0
Brian Williams,11,C,10-29-2008,7.8,8.4,8.5,7.9,8.0
;
/* run; Not required after datalines; */

PROC PRINT data = pumpkins1;
format Enterdate mmddyy10.;
RUN;
PG
Occasional Contributor
Posts: 10

Re: Why i am not able to print j1 ?

EnterDate :mmddyy10. why (Smiley Happy is necessay in input ? is this due to informat and non-standard data.

when do we use colon?
SAS Super FREQ
Posts: 3,483

Re: Why i am not able to print j1 ?

Great question. You can either use an INFORMAT statement or use an informat modifier (Smiley Happy.

 

informat EnterDate mmddyy10.;

input name $ age type $ EnterDate j1-j5;

 

-OR-

input name $ age type $ EnterDate : mmddyy10. j1-j5;

 

 

 

Occasional Contributor
Posts: 10

Re: Why i am not able to print j1 ?

Thanks for answering specifically input.

Why (Smiley Happy is necessary in EnterDate : mmddyy10.

can't EnterDate mmddyy10. work in input?
SAS Super FREQ
Posts: 3,483

Re: Why i am not able to print j1 ?

Please read the link the documentation that i provided.

Ask a Question
Discussion stats
  • 7 replies
  • 339 views
  • 2 likes
  • 5 in conversation