DATA Step, Macro, Functions and more

SAS Invalid data errors

Reply
New Contributor
Posts: 2

SAS Invalid data errors

[ Edited ]
dm "out;clear;log;clear";
title1 'Homework_5_';
options pageno=1 formchar="|----|+|---+=|-/\<>*";
filename hw5 'C:\users\kan\hw5.txt';
libname sds 'c:\users\kan';
data work.hw5a;
infile hw5 lrecl=100 pad;
input ID $ 1-3 Admission mmddyy6. Discharge mmddyy8. Birth mmddyy8. Lastname $ 27-38;
format Admission mmddyy6. Discharge mmddyy8. Birth mmddyy10.;
proc contents data=work.hw5a;
run;
proc print data=work.hw5a;
run;
data hw5b;
infile hw5 lrecl=100 pad;
retain admit disch dob age month lastname;
input ID $ 3. m 2. d 2. y 2. disch mmddyy8. dob mmddyy8. last $ 27-38;
input age month last;
month=m;
lastname=upcase(last);
admit=mdy(m,d,y);
format admit mmddyy8. disch mmddyy8. dob mmddyy10.;
drop m d y;
age=int((admit-dob)/365);
RETAIN my_id 0;
my_id=sum(my_id,666);
RETAIN Oldest;
Oldest=max(Oldest,age);


proc contents data=hw5b;
run;
proc print data=hw5b;
run;

I am getting these messages in the log. How can I fix this?

OTE: Invalid data for age in line 2 1-25.
NOTE: Invalid data for month in line 2 27-32.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+-
3 00305129206/09/9212251899 milleR
87
NOTE: Invalid data errors for file HW5 occurred outside the printed range.
NOTE: Increase available buffer lines with the INFILE n= option.
admit=01/05/92 disch=01/07/92 dob=10/21/1946 age=45 month=1 lastname=00305129206/ ID=001 m=1 d=5
y=92 last=00305129206/ my_id=666 Oldest=45 _ERROR_=1 _N_=1
NOTE: LOST CARD.
admit=01/05/92 disch=01/07/93 dob=04/05/1952 age=45 month=1 lastname=00305129206/ ID=004 m=1 d=1
y=93 last=Smith-Jones my_id=666 Oldest=45 _ERROR_=1 _N_=2
NOTE: 6 records were read from the infile HW5.
The minimum record length was 0.
The maximum record length was 37.
NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
NOTE: The data set WORK.HW5B has 1 observations and 10 variables.
NOTE: DATA statement used (Total process time):
real time 0.05 seconds
cpu time 0.03 seconds

 

 These are my Data:

00101059201/07/9210211946 jones
00211129211/15/9209011955 Taylor
00305129206/09/9212251899 milleR
00401019301/07/9304051952 Smith-Jones

Super User
Posts: 22,850

Re: SAS Invalid data errors

Discharge Date -> mmddyy8.

But it looks like: 06/09/92 -> This is 10 characters not 8. 

 

You also have two input statements so SAS thinks it's reading two lines each iteration which doesn't match your data.

 

input ID $ 3. m 2. d 2. y 2. disch mmddyy8. dob mmddyy8. last $ 27-38;
input age month last;
Spoiler

Nk25 wrote:
dm "out;clear;log;clear";
title1 'Homework_5_';
options pageno=1 formchar="|----|+|---+=|-/\<>*";
filename hw5 'C:\users\kan\hw5.txt';
libname sds 'c:\users\kan';
data work.hw5a;
infile hw5 lrecl=100 pad;
input ID $ 1-3 Admission mmddyy6. Discharge mmddyy8. Birth mmddyy8. Lastname $ 27-38;
format Admission mmddyy6. Discharge mmddyy8. Birth mmddyy10.;
proc contents data=work.hw5a;
run;
proc print data=work.hw5a;
run;
data hw5b;
infile hw5 lrecl=100 pad;
retain admit disch dob age month lastname;
input ID $ 3. m 2. d 2. y 2. disch mmddyy8. dob mmddyy8. last $ 27-38;
input age month last;
month=m;
lastname=upcase(last);
admit=mdy(m,d,y);
format admit mmddyy8. disch mmddyy8. dob mmddyy10.;
drop m d y;
age=int((admit-dob)/365);
RETAIN my_id 0;
my_id=sum(my_id,666);
RETAIN Oldest;
Oldest=max(Oldest,age);


proc contents data=hw5b;
run;
proc print data=hw5b;
run;

I am getting these messages in the log. How can I fix this?

OTE: Invalid data for age in line 2 1-25.
NOTE: Invalid data for month in line 2 27-32.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+-
3 00305129206/09/9212251899 milleR
87
NOTE: Invalid data errors for file HW5 occurred outside the printed range.
NOTE: Increase available buffer lines with the INFILE n= option.
admit=01/05/92 disch=01/07/92 dob=10/21/1946 age=45 month=1 lastname=00305129206/ ID=001 m=1 d=5
y=92 last=00305129206/ my_id=666 Oldest=45 _ERROR_=1 _N_=1
NOTE: LOST CARD.
admit=01/05/92 disch=01/07/93 dob=04/05/1952 age=45 month=1 lastname=00305129206/ ID=004 m=1 d=1
y=93 last=Smith-Jones my_id=666 Oldest=45 _ERROR_=1 _N_=2
NOTE: 6 records were read from the infile HW5.
The minimum record length was 0.
The maximum record length was 37.
NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
NOTE: The data set WORK.HW5B has 1 observations and 10 variables.
NOTE: DATA statement used (Total process time):
real time 0.05 seconds
cpu time 0.03 seconds

 

 These are my Data:

00101059201/07/9210211946 jones
00211129211/15/9209011955 Taylor
00305129206/09/9212251899 milleR
00401019301/07/9304051952 Smith-Jones


 

 

 

 

 

 

Super User
Posts: 9,580

Re: SAS Invalid data errors

Why do you have a separate input statement for age, month and last in your second data step, when you actually calculate them from other values?

(this statement

lastname=upcase(last);

should be

last=upcase(lastname);

IMO)

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
New Contributor
Posts: 2

Re: SAS Invalid data errors

It worked!
Thanks!
Ask a Question
Discussion stats
  • 3 replies
  • 104 views
  • 1 like
  • 3 in conversation