DATA Step, Macro, Functions and more

Invalid numeric data error

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

Invalid numeric data error

This is my code:

 

data amt2.value_labels;
set amt2.assignment2;
if gender = 0 then gender = 'Male';
run;

 

This converted all the values with zero to .

 

Error Message:

NOTE: Character values have been converted to numeric values at the places given by: (Line)Smiley SadColumn).
64:29
NOTE: Invalid numeric data, 'Male' , at line 64 column 29.
storeid=1 hlthfood=0 size=2 org=2 custid=1 gender=. shopfor=1 veg=0 style=1 usecoup=3 week=1 seq=4 carry=0 coupval=4 amtspent=215.28
 
Any Solutions?.

Accepted Solutions
Solution
‎06-16-2017 03:29 AM
PROC Star
Posts: 742

Re: Invalid numeric data error

Posted in reply to Sakthivel_Saran

You are trying to assign a character value to a numeric variable, that is why you get an error. Write the value 'Male' to a vairble suct as genderc and yo will be fine

 

data amt2.value_labels;
set amt2.assignment2;
if gender = 0 then genderc = 'Male';
run;

View solution in original post


All Replies
Solution
‎06-16-2017 03:29 AM
PROC Star
Posts: 742

Re: Invalid numeric data error

Posted in reply to Sakthivel_Saran

You are trying to assign a character value to a numeric variable, that is why you get an error. Write the value 'Male' to a vairble suct as genderc and yo will be fine

 

data amt2.value_labels;
set amt2.assignment2;
if gender = 0 then genderc = 'Male';
run;
Super User
Posts: 11,343

Re: Invalid numeric data error

Posted in reply to Sakthivel_Saran

Or skip the new variable entirely.

I am guessing that a value of 1 may be female. If different change the vale in proc format code from 1 to the appropriate value.

If you have more values for gender then add additional code values.

 

proc format library=work;
value mygender
0= 'Male'
1= 'Female'
;

proc print data=amt2.assignment2;
   var gender;
   format gender mygender.;
run;

Custom formats can be used to display different text for the same variable in different places. For instance you may have a need for a display of single letter for gender, so you make a different named format (the first word after VALUE above) and only have M and F as values, or you want to display something like "** Male **", a different format and use. Groups of codes can also be assigned to single

 

display value that will be honored by most procedures.

 

Especially with large data sets creating a new format may be much more time efficient than duplicating a data set just to get a different display.

And you can use formats for character variables in a similar way.

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 161 views
  • 0 likes
  • 3 in conversation