notdigit

Reply
Contributor
Posts: 68

notdigit

How do I use notdigit to correct invalid numeric data?

Super User
Posts: 11,134

Re: notdigit

NOTDIGIT works with character values. And all it would do was to tell the first position of a non-digit character in the variable.

If the data is numeric then it won't help at all. Can you provide some examples of the invalid data and the desired correction and rules for correction?

Contributor
Posts: 68

Re: notdigit

Wow, thanks for that since I reached the same conclusion EARLY on. Regardless, here it is. I am using a LARGE data set, and the error msg:

NOTE: Invalid argument to function INPUT at line 21 column 48.

I need to id the obs where this is happening. If I count the lines in code beg with my options; I find a var... Now what run a freq with that var...? This is not my code (inherited). Thanks!

Contributor
Posts: 68

Re: notdigit

This was actually the first note I was referencing when I began here, however it disappeared and since the error is data related to another program (again, inherited) I included a corresponding error msg. Complicated but not really.

NOTE: Invalid numeric data, temp_OTHER_WORK_ACTIVITIES='K' , at line 22 column 173.

Super User
Posts: 11,134

Re: notdigit

I have to assume now that since there is an error with INPUT function that the variable is Character (not numeric as stated previously).

If the values do not contain decimals or commas a start is:

If notdigit(variable)>0 then do;

<some code>

end;

If I were building a data set with such an issue I might be tempted to start with:

data examine;

     set have ;

     RecordNumber= _n_;

    if variable=.; /*This variable being the one that is going to be missing when the INPUT function had invalid input values.*/

end;

If I have a suspicion which variables are possible culprits and the number of variables is significant I might also reduce this examination set with a Keep statement.

That would let me look for patterns within the data that yield that result. RecordNumber will the observation number(s) with the problem data.

I've done enough code archeology to sympathize with inherited code and changed data inputs. But when I see "numeric data" in a question that is what I can address, not "character data that is masquerading as numeric".

Contributor
Posts: 68

Re: notdigit

Getting acquainted with administrative, messy, large data prevents a timely response. The Keep stmt was a no-brainer, so thanks for the reminder and the RecordNumber = _n_ seems to be returning promising results. Thank you!

I'll be back on the input errors shortly after I try some of this there as well. Thank you!!!

Contributor
Posts: 68

Re: notdigit

ballardw I meant a no-brainer for me, that I should have realized, and didn't, just to be clear. I very much appreciate the reminder and the help. Thank you!.

Contributor
Posts: 68

Re: notdigit

I thought I successfully removed values for 3 vars replacing '.' with '0'  (there were many) however what is required is to convert values that are not numeric, e.g. "K', for obs for these 3 vars. Something like, RecordNumber = _n_; if var = notdigit;

Contributor
Posts: 68

Re: notdigit

What I don't understand is why creator used *1 for conversion from char to numeric, rather than input function. Because they are savy progammer, there is likely a good reason. Thinking I might do so for just those 3 vars. I do not want to rewrite all the code (very long).

Super User
Posts: 11,134

Re: notdigit

The core reason for the *1 approach could well be that  was the first way someone showed the original programmer and then never changed programming style.

Contributor
Posts: 68

Re: notdigit

Thanks.

Perhaps. SAS is supposed to convert non-numerics to '.' on a conversion, but this did not happen. I'm tired of this problem, since I have a much bigger sas problem awaiting.

Contributor
Posts: 68

Re: notdigit

NOTE: Invalid argument to function INPUT at line 3403 column 17. Macro (inherited) code with many renames, do loops and character to numeric conversions. Do not know where to start. Pardon my frustration. Any help is appreciated.

Super User
Posts: 11,134

Re: notdigit

Usually the invalid argument note includes a dump of values currently  assigned to variables and an _N_ = ;

The _N_ tells you which record(s) in the input data have the problem. If the code is buried in a macro you may need to turn options MPRINT and/or SOURCE on to get a better idea of which line 3403 may be. Column 17 on that line is likely to have the function called that is having an issue with the value of a variable. If you can identify that line and the function then look in the data dump for the variables used. The problem value is often pretty obvious, missing, character when should be numeric and can't be cast as numeric are likely culprits. Hard to diagnose without data/log/code. You may want to start a new thread.

Contributor
Posts: 68

Re: notdigit

Thank you. I started a new thread, although my help here seems more powerful. But I take advice. I am going back to try the MPRINT and Source. Yes the dump is there, and I believe you when you write is should be pretty obvious. My problem is I am learning this messy data still. One of my problems is the code take almost 2 hours to run, so figuring out how to triage without waiting 2+ hours a run would be smart. Thank you.

Super User
Super User
Posts: 6,845

Re: notdigit

You could probably use the ?? modifier to suppress the automatic error message and produce your own message.

data check ;

  input str $12. ;

  num = input(str,?? 12.);

  list;

  if missing(num) and not missing(str) then put

     'WARNING: Invalid numeric value. ' _n_ = str= :$quote. ;

cards;

123.4

5.6

10E36

What is this?

run;

Ask a Question
Discussion stats
  • 15 replies
  • 602 views
  • 7 likes
  • 3 in conversation