How to eliminate data error notes from the SAS log

0

saslogA student in a SAS class recently asked if there were a way to eliminate data error notes from the SAS log and, instead, write them to a separate file.  Of course there's a way!

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!

options errors=0;

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!

For more datastep tricks, you may wish to attend SAS Programming 2: Data Manipulation Techniques.

Share

About Author

Jim Simon

Principal Technical Training Consultant

Jim Simon is a principal instructor and course developer for SAS Education. Jim has a bachelor's degree from UCLA and a master's degree from California State University at Northridge. Prior to joining the SAS Irvine office in 1988, Jim was an instructor at Ventura College and a SAS programmer at The Medstat Group in Santa Barbara. Jim's areas of specialization include the DATA step, application development, web enablement, and the SAS macro language. A native of Southern California, Jim enjoys anything in the warm California sun. On weekends, Jim loves jumping in his Corvette, turning up the stereo, and cruising Pacific Coast Highway, top down, South to Laguna Beach or North to his old home town, Santa Barbara.

Related Posts

Leave A Reply

Back to Top