Help using Base SAS procedures

Why this warning in numeric to charactoer conversion?

Accepted Solution Solved
Reply
Super Contributor
Posts: 338
Accepted Solution

Why this warning in numeric to charactoer conversion?

Hi SAS Forum,

The  variable named “account_number” in dataset A is a numeric (it is sure).

I wanted to convert it into a character.

I used this code.

data B (rename=(account_number_new=account_number));

     set A;

     account_number_new=left(put(account_number, $32.));  /*to convert to character;*/

     drop account_number;

run;

Question:

This warning comes but conversion happened.

WARNING: Variable ACCOUNT_NUMBER has already been defined as numeric.

Could anyone help me to understand why this warning?

Thanks

Mirisage


Accepted Solutions
Solution
‎02-25-2013 04:53 PM
Super Contributor
Posts: 578

Re: Why this warning in numeric to charactoer conversion?

Should be

account_number_new=left(put(account_number, 32.));  /*to convert to character;*/

View solution in original post


All Replies
Solution
‎02-25-2013 04:53 PM
Super Contributor
Posts: 578

Re: Why this warning in numeric to charactoer conversion?

Should be

account_number_new=left(put(account_number, 32.));  /*to convert to character;*/

Occasional Contributor
Posts: 13

Re: Why this warning in numeric to charactoer conversion?

You're going to get the warning regardless, but you should be able to ignore it.  If your PROC Contents shows the variable you want coming out as character, you're doing fine.

Super User
Super User
Posts: 6,502

Re: Why this warning in numeric to charactoer conversion?

The warning message is because you tried to apply a character format ($32.) to a numeric variable.  Use a numeric format like 32. instead.

Occasional Contributor
Posts: 13

Re: Why this warning in numeric to charactoer conversion?

Duh! <smacks self on head> Tom is totally right.

You're using a character informat and applying it to a numeric variable.  The informat that you use in your PUT function should be the same variable type as the incoming source data (in this case numeric).  It will still output the new variable as character.

What I said was also technically kind of true, but that's just because SAS was being nice and forgiving, not because your code was technically correct. Smiley Happy

Super Contributor
Posts: 338

Re: Why this warning in numeric to charactoer conversion?

Hi DBailey, Tom and Tasha,

Many thanks to eveyone of you for this help.

Regards

Mirisage

🔒 This topic is solved and locked.

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

Discussion stats
  • 5 replies
  • 225 views
  • 6 likes
  • 4 in conversation