Hello
I would like to ask please why to_date column is Null values?
DATA Ex2;
input subj from_date mmddyy8. to_date mmddyy8.;
format from_date to_date date9.;
CARDS;
1024 12/1/05 01/01/02
1167 12/01/05 01/01/08
1168 12/2/05 06/15/07
1201 11/30/05 12/31/06
1302 1/1/06 06/15/08
;
RUN;
Thanks
Joe
Hi, Ronein:
Your wanted is this one?
I just submitted your code, but Variable To_Date is not null.....
Same as @KentaMURANAKA, the code works fine for me.
@Ronein wrote:
Hello
I would like to ask please why to_date column is Null values?
DATA Ex2;
input subj from_date mmddyy8. to_date mmddyy8.;
format from_date to_date date9.;
CARDS;
1024 12/1/05 01/01/02
1167 12/01/05 01/01/08
1168 12/2/05 06/15/07
1201 11/30/05 12/31/06
1302 1/1/06 06/15/08
;
RUN;
Thanks
Joe
Your code is using FIXED column positions. But the data you posed it NOT in fixed columns.
The reason others can run it is probably because you are reading from the in-line data which will be padded out to 80 columns (or next multiple of 80).
If we put your example data into an external file and try to read it with that INPUT statement you can see the problem. Especially if we make a line with a short FROM_DATE earlier than then last line.
filename sample temp;
data _null_;
file sample;
input line $char60. ;
len=length(line);
put line $varying60. len ;
CARDS;
1024 2/1/05 01/01/02
1167 12/01/05 01/01/08
1168 12/2/05 06/15/07
1201 11/30/05 12/31/06
1302 1/1/06 06/15/08
;
DATA Ex2;
infile sample;
input subj from_date mmddyy8. to_date mmddyy8.;
format from_date to_date date9.;
run;
1554 DATA Ex2; 1555 infile sample; 1556 input subj from_date mmddyy8. to_date mmddyy8.; 1557 format from_date to_date date9.; 1558 run; NOTE: The infile SAMPLE is: Filename=C:\Users\...\#LN00053, RECFM=V,LRECL=32767,File Size (bytes)=115, Last Modified=17Jun2018:11:47:38, Create Time=17Jun2018:11:47:38 NOTE: Invalid data for to_date in line 2 1-8. RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+-- 2 1167 12/01/05 01/01/08 22 subj=1024 from_date=01FEB2005 to_date=. _ERROR_=1 _N_=1 NOTE: LOST CARD. subj=1302 from_date=01JAN2006 to_date=. _ERROR_=1 _N_=4 NOTE: 5 records were read from the infile SAMPLE. The minimum record length was 20. The maximum record length was 22. NOTE: SAS went to a new line when INPUT statement reached past the end of a line. NOTE: The data set WORK.EX2 has 3 observations and 3 variables.
It looks like your data is space delimited so just use LIST mode input instead of FORMATTED input. You could simply add colon prefix before the informat specifications in your INPUT statement.
input subj from_date :mmddyy8. to_date :mmddyy8.;
But you probably also want to add the TRUNCOVER option to your INFILE statement to prevent SAS from hunting to the next line if the current line does not have enough data to satisfy the INPUT statement.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.