BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

I want to create a binary variable that check if char var contain only numbers.

I saw this code in google search 

isnumber = not missing(input(X_Char,?? 32.));

and I want to understand it please.

What is the meaning of ?? 

I see that also this code work well

isnumber = not missing(input(X_Char,best.));

data have;
input X_Char $;
isnumber = not missing(input(X_Char,?? 32.));
datalines;
3.22
4..2
N/A
1.23e7
(a1) 1234
(a2) 2000
8000
Good
;
Run;
5 REPLIES 5
PaigeMiller
Diamond | Level 26

Maxim 1 — Read the Documentation

 

INPUT function documentation

--
Paige Miller
Kathryn_SAS
SAS Employee

You can also use the NOTDIGIT Function 

PaigeMiller
Diamond | Level 26

@Kathryn_SAS wrote:

You can also use the NOTDIGIT Function 


Yes I thought of that, but NOTDIGIT fails for a character string like 3.22

--
Paige Miller
Kathryn_SAS
SAS Employee
Good point and catch.
Tom
Super User Tom
Super User

The ? and ?? modifiers suppress error messages.

 

32 is the maximum number of characters that the normal numeric informat can handle.

 

But if you don't specify the width to use for an informat then SAS will default to 12.  So your two statements are not equivalent as the first one reads the first 32 bytes of the character variable and the second only the first 12.

 

Note that BEST is the name of a FORMAT that tries to find the best way to represent a number in a fixed number of characters.  There is no equivalent meaning of the best way to represent a number as a number so using BEST as the name of an informat is just confusing.  If you do use it that way then SAS will just take at as an alias for the normal numeric informat, the one you used in your first statement. 

 

You could try checking if the string only contains digits.  Or perhaps digits and period.  Or perhaps also include hyphen and plus sign.  But that would yield false positives for values with multiple periods. And it would yield false negatives for values in scientific notation. Note that the BEST format will generate strings in scientific notation when it has to.

 

One thing you might want to consider is using the COMMA (or perhaps COMMAX) informat instead or the normal numeric informat.  That will accept strings with commas in them (and also dollar signs).

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 5 replies
  • 505 views
  • 3 likes
  • 4 in conversation