Here's a simple datastep. Notice the missing dollar sign to indicate the variable GENDER (M, F) is a character variable.
data class;
infile 'c:\temp\class.csv' dsd;
input name $ gender age;
run;
|
We've all seen those ugly data error notes in the SAS log!
562 data class;
563 infile 'c:\temp\class.csv' dsd;
564 input name $ gender age;
565 run;
NOTE: The infile 'c:\temp\class.csv' is:
Filename=c:\temp\class.csv,
RECFM=V,LRECL=32767,File Size (bytes)=236,
Last Modified=03Dec2014:12:46:20,
Create Time=03Dec2014:12:46:20
NOTE: Invalid data for gender in line 1 8-8.
RULE: ----+----1----+----2----+----3----+----4----+----5
1 Alfred,M,14 11
name=Alfred gender=. age=14 _ERROR_=1 _N_=1
NOTE: Invalid data for gender in line 2 7-7.
2 Alice,F,13 10
name=Alice gender=. age=13 _ERROR_=1 _N_=2
NOTE: Invalid data for gender in line 3 9-9.
3 Barbara,F,13 12
name=Barbara gender=. age=13 _ERROR_=1 _N_=3
NOTE: Invalid data for gender in line 4 7-7.
4 Carol,F,14 10
name=Carol gender=. age=14 _ERROR_=1 _N_=4
NOTE: Invalid data for gender in line 5 7-7.
5 Henry,M,14 10
name=Henry gender=. age=14 _ERROR_=1 _N_=5
NOTE: Invalid data for gender in line 6 7-7.
6 James,M,12 10
name=James gender=. age=12 _ERROR_=1 _N_=6
NOTE: Invalid data for gender in line 7 6-6.
7 Jane,F,12 9
name=Jane gender=. age=12 _ERROR_=1 _N_=7
...
NOTE: 19 records were read from the infile 'c:\temp\class.csv'.
The minimum record length was 9.
The maximum record length was 12.
NOTE: The data set WORK.CLASS has 19 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.04 seconds
cpu time 0.04 seconds
|
Suppressing the data error notes in the SAS log is easy!
But the above approach only masks the bad news. That is why the student wanted to write these notes to a separate file. Here's how!
data class;
infile 'c:\temp\class.csv' dsd;
input name $ gender age;
if _error_=1 then do;
file 'c:\temp\MyInvalidDataNotes.txt';
put 'NOTE: Invalid data in line ' _N_;
put _infile_;
put _all_;
put;
end;
run;
|
In SAS, there's always a way!
No comments:
Post a Comment