DATA Step, Macro, Functions and more

Supress error message

New Contributor
Posts: 4

Supress error message

I am reading a field that can either be a packed numeric (PD2.) or an alpha character ($2.). Since I only care if it is a number, I am reading it as PD2. format. I know I can limit the number of error messages, but is there a way to suppress the message when it encounters a character value in this field?
Not applicable
Posts: 0

Re: Supress error message


since you are not interested in alpha character maybe is a good idea not to read those values (and by the way values are read with INFORMATS, with FORMATS you just print the values in a suitable way):

data test (drop=x);
infile datalines;
length x $2.;
input x @;
if ANYALPHA(x) then return;
else input @1 a 2.;

Super Contributor
Super Contributor
Posts: 3,176

Re: Supress error message

Posted in reply to deleted_user
Also, with your INPUT statement (or with using the INPUT function), you can specify a "?" character ahead of the INFORMAT with some additional overhead.

Scott Barry
SBBWorks, Inc.
Super User
Posts: 10,787

Re: Supress error message

Just as Sbb said .
Do you try ' input x ?? comma8.'
is double ? not single ?

Super Contributor
Super Contributor
Posts: 3,176

Re: Supress error message

Good point, Ksharp. Yes, the SAS behavior differs with one- or two- question-marks specified, as documented here:

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

input function informat question mark
New Contributor
Posts: 4

Re: Supress error message

THANKS everyone! The ?? worked... Also good to know about the ANYALPHA function -- I can think of a couple other programs where I which I had known about that one...
Valued Guide
Posts: 765

Re: Supress error message

hi ... another idea ...

* create a numeric INFORMAT;
proc format;
invalue mixed
low-high = [10.]

* use MIXED. to read "mixed data";
data test;
input x : mixed. @@;
1234 e2 56446 hf fy 5474

the LOG ... no errors ...

90 data test;
91 input x : mixed. @@;
92 datalines;

NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
NOTE: The data set WORK.TEST has 6 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

the data set ...

Obs x
1 1234
2 .
3 56446
4 .
5 .
6 5474

for your data, you should be able to replace [10.] in the informat with [PD2.]
Ask a Question
Discussion stats
  • 6 replies
  • 5 in conversation