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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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