SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
joegee
Calcite | Level 5
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
deleted_user
Not applicable
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
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
Ksharp
Super User
Just as Sbb said .
Do you try ' input x ?? comma8.'
is double ? not single ?


Ksharp
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
joegee
Calcite | Level 5
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...
MikeZdeb
Rhodochrosite | Level 12
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.]

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2814 views
  • 0 likes
  • 5 in conversation