- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 01-12-2011 03:04 PM
(2813 views)
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?
6 REPLIES 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
hello,
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.;
output;
datalines;
1234
e2
56446
hf
fy
5474
;
Marius
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.;
output;
datalines;
1234
e2
56446
hf
fy
5474
;
Marius
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Scott Barry
SBBWorks, Inc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Just as Sbb said .
Do you try ' input x ?? comma8.'
is double ? not single ?
Ksharp
Do you try ' input x ?? comma8.'
is double ? not single ?
Ksharp
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Good point, Ksharp. Yes, the SAS behavior differs with one- or two- question-marks specified, as documented here:
http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a000180357.htm
Scott Barry
SBBWorks, Inc.
Suggested Google advanced search argument, this topic / post:
input function informat question mark site:sas.com
http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a000180357.htm
Scott Barry
SBBWorks, Inc.
Suggested Google advanced search argument, this topic / post:
input function informat question mark site:sas.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
hi ... another idea ...
* create a numeric INFORMAT;
proc format;
invalue mixed
low-high = [10.]
other=.
;
run;
* use MIXED. to read "mixed data";
data test;
input x : mixed. @@;
datalines;
1234 e2 56446 hf fy 5474
;
run;
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.]
* create a numeric INFORMAT;
proc format;
invalue mixed
low-high = [10.]
other=.
;
run;
* use MIXED. to read "mixed data";
data test;
input x : mixed. @@;
datalines;
1234 e2 56446 hf fy 5474
;
run;
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.]