BookmarkSubscribeRSS Feed
sasuser123123
Quartz | Level 8
I have data
Mixed
Johnroy
17533
45688
BET32L
MINE20
56
12
ALPHA65

So I need to create new variable that contains only numeric values I tried below code..
Data BMW;
Set existing;
If ~missing(compress(mixed,,"kd")) then Number=input(name,best.);
Run;

When I ran this code I got note as INVALID Argument to the function INPUT.....How to handle this situation..I put ?? before best. it works but I'm not satisfied with that one because it suppresses that note ..is there any possibilities to do that job...
5 REPLIES 5
Astounding
PROC Star

That sounds strange.  You added ?? to get rid of the note, and now you're unhappy because you're not getting the note?

 

While you're on the road to correcting the problem, consider what the result should be for each of these inputs:

 

MINE20

3.14

A1B2C3

-40

WD10-40

 

Clarifying your objective would help in developing the right program.

sasuser123123
Quartz | Level 8
Without giving ?? I'm getting output with correct values..but also getting note:
Invalid argument for Input function..
ballardw
Super User

See if this gives you a likely clue:


If ~missing(compress(mixed,,"kd")) then Number=input(name,best.);

I think that you meant to use mixed in both places.

If not then you need to provide values for NAME.

If the variable NAME has not been defined prior to this statement then it was created as NUMERIC, with missing values. Then the missing numeric value was attempted to turn into character for use by the INPUT function.

sasuser123123
Quartz | Level 8
I apologized for that mistake..it's not Name it's mixed.
I tried new way now I'm getting

If ~missing(compress(mixed,,"kd")) And missing(compress(mixed, , "d") then number=input(mixed,best.)
Kurt_Bremser
Super User

Use the NOTDIGIT function. Your condition will return true if there's any digit in the string.

data want;
input mixed $10.;
if notdigit(mixed) = 0 then number = input(mixed,best.);
datalines;
Johnroy
17533
45688
BET32L
MINE20
56
12
ALPHA65
;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 923 views
  • 0 likes
  • 4 in conversation