DATA Step, Macro, Functions and more

Character values have been converted to numeric values when entering .k as a number.

Reply
Regular Contributor
Posts: 235

Character values have been converted to numeric values when entering .k as a number.

hi,

at my client i have to put .K (which corresponds with not known), .V , .D ... possible in a numeric field. As it begins with a . SAS accepts it.

var&i = .K

But i'm getting this errors... any help?

NOTE: Character values have been converted to numeric values at the places given by: (Line)Smiley SadColumn).

      17:17    17:77    17:137   17:197   19:17    19:77    19:137   19:197   21:17    21:77    21:137   21:197   23:17    23:77    23:137   23:197   25:17    25:77

      25:137   25:197   27:17    27:77    27:137   27:197   29:17    29:77    29:137   29:197   31:17    31:77    31:137   31:197

Frequent Contributor
Posts: 139

Re: Character values have been converted to numeric values when entering .k as a number.

Please post with code and some example what you want to achieve

Regular Contributor
Posts: 235

Re: Character values have been converted to numeric values when entering .k as a number.

Posted in reply to manojinpec

underneath my datastep, the result is ok

For example:

AEENMTH is numeric, and has as value K after running the datastep. But I think i'm getting some "Notes" because of that:

NOTE: Character values have been converted to numeric values at the places given by: (Line)Smiley SadColumn).

      17:17    17:77    17:137   17:197   19:17    19:77    19:137   19:197   21:17    21:77    21:137   21:197   23:17    23:77    23:137   23:197   25:17    25:77

      25:137   25:197   27:17    27:77    27:137   27:197   29:17    29:77    29:137   29:197   31:17    31:77    31:137   31:197

Is there a way to rewrite the code, to not get this note?

Datastep:

data current.AE;

set AE_temp;

if (AEACN = '' and _AEACN = 1) then AEACN = .K ;

else if (AEACN = '' and _AEACN = 2) then AEACN = .V ;

else if (AEACN = '' and _AEACN = 3) then AEACN = .D ;

else if (AEACN = '' and _AEACN = 4) then AEACN = .A ;

drop _AEACN ;

if (AEENDT = '' and _AEENDT = 1) then AEENDT = .K ;

else if (AEENDT = '' and _AEENDT = 2) then AEENDT = .V ;

else if (AEENDT = '' and _AEENDT = 3) then AEENDT = .D ;

else if (AEENDT = '' and _AEENDT = 4) then AEENDT = .A ;

drop _AEENDT ;

if (AEENMTH = '' and _AEENMTH = 1) then AEENMTH = .K ;

else if (AEENMTH = '' and _AEENMTH = 2) then AEENMTH = .V ;

else if (AEENMTH = '' and _AEENMTH = 3) then AEENMTH = .D ;

else if (AEENMTH = '' and _AEENMTH = 4) then AEENMTH = .A ;

drop _AEENMTH ;

if (AEREL = '' and _AEREL = 1) then AEREL = .K ;

else if (AEREL = '' and _AEREL = 2) then AEREL = .V ;

else if (AEREL = '' and _AEREL = 3) then AEREL = .D ;

else if (AEREL = '' and _AEREL = 4) then AEREL = .A ;

drop _AEREL ;

if (AEREL2 = '' and _AEREL2 = 1) then AEREL2 = .K ;

else if (AEREL2 = '' and _AEREL2 = 2) then AEREL2 = .V ;

else if (AEREL2 = '' and _AEREL2 = 3) then AEREL2 = .D ;

else if (AEREL2 = '' and _AEREL2 = 4) then AEREL2 = .A ;

drop _AEREL2 ;

if (AESEV = '' and _AESEV = 1) then AESEV = .K ;

else if (AESEV = '' and _AESEV = 2) then AESEV = .V ;

else if (AESEV = '' and _AESEV = 3) then AESEV = .D ;

else if (AESEV = '' and _AESEV = 4) then AESEV = .A ;

drop _AESEV ;

if (AESTDT = '' and _AESTDT = 1) then AESTDT = .K ;

else if (AESTDT = '' and _AESTDT = 2) then AESTDT = .V ;

else if (AESTDT = '' and _AESTDT = 3) then AESTDT = .D ;

else if (AESTDT = '' and _AESTDT = 4) then AESTDT = .A ;

drop _AESTDT ;

if (AESTMTH = '' and _AESTMTH = 1) then AESTMTH = .K ;

else if (AESTMTH = '' and _AESTMTH = 2) then AESTMTH = .V ;

else if (AESTMTH = '' and _AESTMTH = 3) then AESTMTH = .D ;

else if (AESTMTH = '' and _AESTMTH = 4) then AESTMTH = .A ;

drop _AESTMTH ;

run;

Regular Contributor
Posts: 151

Re: Character values have been converted to numeric values when entering .k as a number.

very simple, = ' ' refers to a character missing value.  You're applying it to a numeric variable, so it is converting the character missing value to a numeric missing value.

You can either change ' ' to . which is the default missing numeric value, or use missing(varname) which applies to both character and numeric variables (and will also pick up special missing numeric values such as .K)

Regular Contributor
Posts: 235

Re: Character values have been converted to numeric values when entering .k as a number.

thanks.. did not focused on that part.. though it could be possible that I don't know if the variable is numeric or character...

Regular Contributor
Posts: 151

Re: Character values have been converted to numeric values when entering .k as a number.

If you're not sure of the variable type then use the MISSING function, although if you're assigning a new value then you obviously need to know which type to use!

It's not covered in the scope of you question, but your code can be simplified using either of the 2 methods below.  This saves checking for the missing value each time.

if missing(AEACN) then do;

         if _AEACN = 1 then AEACN = .K;         

  else if _AEACN = 2 then AEACN = .V;

  else if _AEACN = 3 then AEACN = .D;

  else if _AEACN = 4 then AEACN = .A;

end;

drop  _AEACN;

if missing(AEACN) then do;

  select (_AEACN);

   when (1) AEACN = .K;

   when (2) AEACN = .V;

   when (3) AEACN = .D;

   when (4) AEACN = .A;

  otherwise end;

end;

drop _AEACN;

Ask a Question
Discussion stats
  • 5 replies
  • 1303 views
  • 0 likes
  • 3 in conversation