DATA Step, Macro, Functions and more

Note: Invalid numeric data

Reply
Contributor
Posts: 73

Note: Invalid numeric data

Hi,

I'm getting a

NOTE: Invalid numeric data, Disposition='TREATED TRANSPORTED', at line

353 column 8.

 

I have the following code:

 

data new;

set test;

if Disposition= 'Canceled, No Patient Contact' then Disposition= 'Canceled';

if Disposition= 'Unresponsive– Pronounced' or Disposition eq 'dead' then Disposition='Dead';

if Disposition= 'Treated Transported' or Disposition= 'Treated and transported' then Disposition='TREATED TRANSPORTED';

if Disposition= 'Treated and Released (per protocol)' then Disposition='Treated and Released';

run;

 

 

NOTE: Invalid numeric data, Disposition='TREATED TRANSPORTED' , at line

353 column 8.

 

I looked at other previous responses to Invalid numeric data errors, but I didn't get the answer for this. I tried all the suggestions but they didn't work for my code.

 

Can anybody help me with this.

 

Thank you

M

Super Contributor
Super Contributor
Posts: 265

Re: Note: Invalid numeric data

Posted in reply to Malathi13

I would guess looking at the data in line 353 of test would be a place to start.

 

Contributor
Posts: 73

Re: Note: Invalid numeric data

Thank you, I got the answer!!. One of the observation was numeric in that Variable, I deleted that and I got the answer.

Super User
Super User
Posts: 7,860

Re: Note: Invalid numeric data

[ Edited ]
Posted in reply to Malathi13

Malathi13 wrote:

Thank you, I got the answer!!. One of the observation was numeric in that Variable, I deleted that and I got the answer.


Glad you fixed your problem, but that statement makes no sense. A variable has the same type for every observation in a dataset. SAS datasets are not spreadsheets.  And even if your error was caused by code that was attempting to convert a character variable into a number such as :

disposition = disposition + 1;

then ithe one observation that held a string that looked like a number that would be the one that did NOT generate an error or warning.

 

Contributor
Posts: 73

Re: Note: Invalid numeric data

Hi All,

Thank you for your suggestions. 

 

Tom, 

 to give you an expiation of my data, variable disposition is character but one of the observation in that variable as 1.

 

E.x.   Dispostion

          Treated

          Treated and Transported

          Dead

          1

          Transferred

          Pronounced Dead

 

that's what I have in the dataset for Variable Disposition. When I used if-then to delete, I used

if disposition='Treated" then disposition='Treated and Transported';

if deposition=1 then delete;

if disposition='Pronounced Dead' then disposition='Dead';

 

that's when I was getting that NOTE: Invalid numeric error. I fixed it by adding quotations to 1 (see below) and my error got fixed.

 

if disposition='1' then delete;

 

 

Thank you

M

PROC Star
Posts: 8,117

Re: Note: Invalid numeric data

Posted in reply to Malathi13

Now the error you received makes perfect sense and, yes, putting quotes around the 1 will resolve that particular error.

 

However, you code has other mistakes. e.g.:

if disposition='Treated" then disposition='Treated and Transported';

You can't mix single and double quotes. It would have to be either 'Treated' or "Treated"

 

if deposition=1 then delete;

Are you trying to evaluate desposition or disposition?

 

Art, CEO, AnalystFinder.com

 

Contributor
Posts: 73

Re: Note: Invalid numeric data

I made error in typing but the code I have is correct. Sorry for spelling mistakes. It’s disposition and in my actual code I have single quotes. I did see that I mixed the codes here while writing. It’s ‘Treated’ not ‘Treated”. Good catch.
Trusted Advisor
Posts: 1,828

Re: Note: Invalid numeric data

Posted in reply to Malathi13

I guess DISPOSITION is defined as numeric in your input with a format displaying text.

 

1) Run proc contents for your input dataset. Is this field realy defined as numeric ? and what format is attached to it ?

 

proc contents data=test; run;

 

2) Assuming there is a format then run:

   

proc format lib=<format catalog library> list;
   select <format name>;
run;

   then replace your code to check for the numeric code and assign numeric code - instead dealing with textual value.

 

 

3) Alternatively you can use PUT/INPUT functions with the format/informat to create a new char type variable.

       

 

 

PROC Star
Posts: 8,117

Re: Note: Invalid numeric data

Posted in reply to Malathi13

I would run proc contents on the dataset. Sounds like disposition is actually a numeric field and what you really want to do is change the format that is being applied to it.

 

Art, CEO, AnalystFinder.com

 

Super User
Posts: 13,084

Re: Note: Invalid numeric data

Posted in reply to Malathi13

Try copy and pasting the entire code and messages from the log for that data step into a code box opened with the forum {I} menu icon.

We cant tell which line or column of our code (though I can guess I hate doing that).

 

If you do this sort of thing frequently then you might want to learn the select statement

 

select (Disposition); 
   When ('Canceled, No Patient Contact')  Disposition= 'Canceled';
   When ('Unresponsive– Pronounced', 'dead')  Disposition='Dead';
   When ('Treated Transported' ,'Treated and transported')  Disposition='TREATED TRANSPORTED';
   When ('Treated and Released (per protocol)'  Disposition='Treated and Released';
   otherwise; /* do nothing*/
end;
Super Contributor
Super Contributor
Posts: 265

Re: Note: Invalid numeric data

@ballardw That is both new to me and very slick.
Super User
Posts: 13,084

Re: Note: Invalid numeric data


HB wrote:
@ballardw That is both new to me and very slick.

@HB Select is very good way to deal with things that many folks do multiple if/then/else. Note that the When result can also be a DO/End block of code.

The main obstacle is dealing with ranges of numeric as order can become very important such as with:

 grade = select
   when (score >= 90) 'A'
   when (score >= 80) 'B'
   when (score >= 70) 'C'
   when (score >= 60) 'D'
   when (score >= 0 ) 'F'
 end;

 

Note that changing the order of the whens above could result in a significantly different grade.

Which points a modification of my earlier post which is left to the interested reader.

Ask a Question
Discussion stats
  • 11 replies
  • 193 views
  • 1 like
  • 6 in conversation