Help using Base SAS procedures

Invalid numeric data error

Accepted Solution Solved
Reply
Contributor
Posts: 27
Accepted Solution

Invalid numeric data error

Hi all,

I have the following code:

data temp3;

  set temp2;

  format _date date9.;

  _date = mdy(scan(date,1,'/'),scan(date,2,'/'),scan(date,3,'/'));

run;

The weird thing is that _date exists for some values, but for other values I get the following errors:

NOTE: Character values have been converted to numeric values at the places given by:

      (Line)Smiley SadColumn).

      1735:17   1735:48   1735:79

NOTE: Invalid numeric data, '.6' , at line 1735 column 17.

Patient_ID=487 date=

6/10/2004 _date=. _ERROR_=1 _N_=8

NOTE: Invalid numeric data, '.9' , at line 1735 column 17.

Patient_ID=487 date=

9/10/2004 _date=. _ERROR_=1 _N_=9

NOTE: Invalid numeric data, '.10' , at line 1735 column 17.

Patient_ID=491 date=

10/01/2004 _date=. _ERROR_=1 _N_=11

NOTE: Invalid numeric data, '.4' , at line 1735 column 17.

Patient_ID=492 date=

4/24/2007 _date=. _ERROR_=1 _N_=15

NOTE: Invalid numeric data, '.4' , at line 1735 column 17.

Where are these periods (e.g. '.6') before the number coming from? I've tried to compress them out, but I get the same error.

The weird thing is that the formatting for all the dates are the same, so I don't see why it should work for some, but not all.

Thanks!


Accepted Solutions
Solution
‎05-02-2013 09:54 PM
Trusted Advisor
Posts: 2,115

Re: Invalid numeric data error

try this:

data temp3;

  set temp2;

  FORMAT date $hex20.;

PUT date;

run;

you just want to see what the incoming data look like.  Once you print it, you can look up the codes on the web (they are different depending on your server platform).

View solution in original post


All Replies
Trusted Advisor
Posts: 2,115

Re: Invalid numeric data error

you have some junk in the date character string.  use the $HEXw. format to see just what it is.  I suspect a <CR> or <LF> as the printout goes to a new line before printing the date.

Respected Advisor
Posts: 3,156

Re: Invalid numeric data error

I don't have an answer for your question, but seems to me using informat would be a more straightforward option:

_date=input(date,ANYDTDTE10.);

Haikuo

Contributor
Posts: 27

Re: Invalid numeric data error

@Doc@Duke - SAS doesn't seem to recognize that format.

@haikou - The errors disappeared, but I'm still having the issue that certain dates are not being correctly formatted to a SAS date.

Trusted Advisor
Posts: 2,115

Re: Invalid numeric data error

here is the documentation for the format:

SAS(R) 9.3 Formats and Informats: Reference

Contributor
Posts: 27

Re: Invalid numeric data error

My code looks something like this now:

data temp3;

  set temp2;

  format _date $ hex10.;

  _date = input(date,$hex10.);

run;

When running it, ALL the _date values are now invalid arguments to the input function, with a default value of 2020202020.

Solution
‎05-02-2013 09:54 PM
Trusted Advisor
Posts: 2,115

Re: Invalid numeric data error

try this:

data temp3;

  set temp2;

  FORMAT date $hex20.;

PUT date;

run;

you just want to see what the incoming data look like.  Once you print it, you can look up the codes on the web (they are different depending on your server platform).

Contributor
Posts: 27

Re: Invalid numeric data error

Thank you so much! I ran it and got '0A'x (LF) as the leading character for the problematic values. compress(date,'0A'x) did the trick.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 2118 views
  • 0 likes
  • 3 in conversation