Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

failure to convert from Numeric to Character 1

Status
Not open for further replies.

RinaGreen

Technical User
Mar 8, 2005
31
US
I need to convert numbers to characters as I have quest1 values equal 1 or 2 or 3, or

4, or 5.

I need quest1 field whch is numeric (length 8) into char Y or NO depending on criteria.

However I failed to do it. Moreover log tells me:

NOTE: Character values have been converted to numeric values at the places given by:
(Line):(Column).
6:9 7:7 8:14 9:15 10:9 11:10 13:12 13:29 14:14 16:10

17:10
17:25 18:12 20:17 20:39 21:19 23:18 24:18 25:18 25:41 26:20

28:12
29:12 29:30 30:14 32:13 33:13 33:32 34:15
NOTE: Invalid numeric data, 'Y' , at line 13 column 29.
NOTE: Invalid numeric data, 'N' , at line 18 column 12.
NOTE: Invalid numeric data, 'N' , at line 21 column 19.
NOTE: Invalid numeric data, 'N' , at line 26 column 20.
NOTE: Invalid numeric data, 'Y' , at line 29 column 30.
NOTE: Invalid numeric data, 'Y' , at line 33 column 32.


This is my code:
______________________________________________________________________
data Qrename;

quest1=put(quest1,z1.);

if quest1='1' OR
quest1='2' THEN quest1='Y';
else quest1='N';
RUN;
__________________________________________________________________________
Why it says me that Character values have been converted to numeric values while I am

doing an oposite operation?

What am I doing wrong?

Thank you in advance,

Rina
 
z1 is zoned decimal data if memory serves --- not char - so when you try to make the assignment of ='y' it is trying to assign a char to a numeric - try a C1 instead since it looks like you are not using the zoned number for any caluclation.
 
The message os telling you that it converted character numeric because of this:-
if quest1 = '1'...
it is converting the '1' to a numeric to test it against quest1.
You cannot do what you are trying to do, and even if you could it really is BAD programming.
Create a new field and set its value according to the value of quest1.
If you really really HAVE to have your new character variable named QUEST1, then rename the original quest1 and quest2 when you read them in.
ie
Code:
data Qrename;
  * read in data and rename variables            *;
  set qdset1(rename=(quest1 = quest1_num
                     quest2 = quest2_num));

  * set length and type of new quest1 and quest2 *;
  length quest1-quest2 $1;

  * set values of quest1                         *;
  if quest1_num in(1,2) THEN quest1='Y';
  else quest1='N';
RUN;

Please note though that doing this sort of thing causes confusion and is bad practice. Someone else reading through the code will get really confused about what QUEST1 and QUEST2 are if they miss this step. It makes error tracking/problem solving/future modifications that much harder. I would recommend reading the quest1 variable in as quest1_num or something, and calling it that all the way through, then calling the new variable something else.
I cannot stress this strongly enough. I've had to deal with programs like this in the past and it makes life INCREDIBLY difficult.

 
Hi ChrisW75,

This question should really be a new post. But how do you get the code box to appear in your reply post?

Thanks,

CW
 
At the bottom of the "Your Reply" box, there is a set of tick boxes under "Step2 Options". One of these says "Process TGML" click on the words and it'll open up a list of tags that you can use to change your text entry, very similar to HTML, but in square brackets. Look up "code" in the list.
:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top