DATA Step, Macro, Functions and more

Annoying Note: Numeric values have been converted to character values at the places given by: (Line):(Column).

Accepted Solution Solved
Reply
Contributor
Posts: 35
Accepted Solution

Annoying Note: Numeric values have been converted to character values at the places given by: (Line):(Column).

Hi Experts,

I am trying to remove the notes from my log file, but without success.  I have checked the variable's format, they are consistent with the value I assigned.  Here is part of my log file:

====================

-------------------In LOCF MACRO------------------

NOTE: ENRLL=  FmtVar=$1. FmtRtn=$200.

NOTE: Character Variable: ENRLL

-------------------In LOCF MACRO------------------

NOTE: ENRLLDT=. FmtVar=DATE9. FmtRtn=DATE9.

NOTE: Numeric Variable: ENRLLDT

-------------------In LOCF MACRO------------------

NOTE: SDCRES=DISEASE PROGRESSION FmtVar=$100. FmtRtn=$200.

NOTE: Character Variable: SDCRES

-------------------In LOCF MACRO------------------

NOTE: SDCRESN=5 FmtVar=BEST12. FmtRtn=BEST12.

NOTE: Numeric Variable: SDCRESN

-------------------In LOCF MACRO------------------

NOTE: SDISCDT=06JUN2013 FmtVar=DATE9. FmtRtn=DATE9.

NOTE: Numeric Variable: SDISCDT

-------------------In LOCF MACRO------------------

NOTE: TDCRES=  FmtVar=$100. FmtRtn=$200.

NOTE: Character Variable: TDCRES

-------------------In LOCF MACRO------------------

NOTE: TDCRESN=. FmtVar=BEST12. FmtRtn=BEST12.

NOTE: Numeric Variable: TDCRESN

-------------------In LOCF MACRO------------------

NOTE: TDISCDT=. FmtVar=DATE9. FmtRtn=DATE9.

NOTE: Numeric Variable: TDISCDT

-------------------In LOCF MACRO------------------

NOTE: DEATHDT=. FmtVar=DATE9. FmtRtn=DATE9.

NOTE: Numeric Variable: DEATHDT

......

========================

Here id the program:

======================

%MACRO LOCF(LOCFVar, SortVar, RetainV);


  %IF &_DEBUG = 1 %THEN %DO;

  FmtVar = vformat(&LOCFVar);

  FmtRtn = vformat(&RetainV);

  PUT "-------------------In LOCF MACRO------------------";

  PUT "NOTE: " &LOCFVar= FmtVar= FmtRtn=;

  %END;

  /*If it is a character variable;*/

  IF VTYPE(&LOCFVar)= 'C' THEN DO;

  PUT "NOTE: Character Variable: &LOCFVar";

  /*Initial the variable value at first.byVar;*/

  IF first.&SortVar THEN &RetainV='';

  IF &LOCFVar ^= '' THEN &RetainV = &LOCFVar;

  ELSE &LOCFVar=&RetainV;

  END;

  /*If it is a Numeric variable;*/

  IF VTYPE(&LOCFVar)= 'N' THEN DO;

  PUT "NOTE: Numeric Variable: &LOCFVar";

  /*Initial the variable value at first.byVar;*/

  IF first.&SortVar THEN &RetainV=.;

  IF &LOCFVar ^= . THEN &RetainV=&LOCFVar;

  ELSE &LOCFVar=&RetainV;

  END;

%MEND LOCF;

========================


Accepted Solutions
Solution
‎06-02-2014 01:42 PM
Super User
Super User
Posts: 7,076

Re: Annoying Note: Numeric values have been converted to character values at the places given by: (Line):(Column).

Here is code that does NOT depend on the type of the variable. Only conflict would be if the &RETAINV variable already existed in the data vector.

By making the first reference to the new &RETAINV variable an assignment statement SAS should automatically create it with the same type as the source variable.

%macro locf

(LOCFVar    /* Variable to retain */

,SortVar    /* By var */

,RetainV    /* Temporary variable to use for carry forward */

);

if first.&sortvar then &retainv = &locfvar ;

else if missing(&locfvar) then &locfvar = &retainv ;

else &retainv = &locfvar ;

retain &retainv ;

drop &retainv ;

%mend locf ;

View solution in original post


All Replies
Super User
Posts: 19,869

Re: Annoying Note: Numeric values have been converted to character values at the places given by: (Line):(Column).

You should post the errors you're getting and the relevant lines of code that it refers to. Seeing your code and the output you want doesn't help much.

In general that message appears when you're doing something with a variable where it expects a different type.

Contributor
Posts: 35

Re: Annoying Note: Numeric values have been converted to character values at the places given by: (Line):(Column).

Hi Reeza,

There is no errors, and the results are fine.  I just want to remove these notes.  My log message exactly showed that in the LOCF macro, the variable types and formats are matched the operations. 

Thanks for your reply,

Abdu

Super User
Posts: 5,516

Re: Annoying Note: Numeric values have been converted to character values at the places given by: (Line):(Column).

This is a design consideration, not a SAS quirk.  You have designed the macro so that &LOCFVAR sometimes refers to a numeric value and sometimes refers to a character value.  That design forces SAS to convert at some point. 

Contributor
Posts: 35

Re: Annoying Note: Numeric values have been converted to character values at the places given by: (Line):(Column).

Posted in reply to Astounding

Hi Astounding,

I just do not know which part is causing the notes.   Yes, LOCFVAR could be both character and Numeric, but when the macro code was replaced, LOCFVAR is different entity.  If the format matched, why SAS still give notes?  Some logic behind?

Thanks,

Abdu

Super User
Posts: 11,343

Re: Annoying Note: Numeric values have been converted to character values at the places given by: (Line):(Column).

That is not the program, only a macro that is called by the program. As a minimum the entire datastep including the macro call(s) would likely help diagnose.

Contributor
Posts: 35

Re: Annoying Note: Numeric values have been converted to character values at the places given by: (Line):(Column).

Hi Ballarsw,

The program called this macro is little long.  But I am posting the code entirely, if it helps.

Thanks,

Abdu

Attachment
Super User
Super User
Posts: 7,076

Re: Annoying Note: Numeric values have been converted to character values at the places given by: (Line):(Column).

So you need to change the SAS code that is referencing the variable so that it either uses the right syntax for the variable type or convert to some expression that does not require type conversion by SAS.

For example if &LOCFVAR is numeric then it might be this reference that is generating the note.

  /*Initial the variable value at first.byVar;*/

  IF first.&SortVar THEN &RetainV='';

  IF &LOCFVar ^= '' THEN &RetainV = &LOCFVar;

  ELSE &LOCFVar=&RetainV;


You could convert your code to below to preserve the function and prevent SOME of the notes.

  /*Initial the variable value at first.byVar;*/

  IF first.&SortVar THEN &RetainV='';

  IF missing(&LOCFVar) THEN &RetainV = cats(&LOCFVar) ;

  ELSE &LOCFVar=&RetainV;


But to really get rid of them why not tell the macro what TYPE to variable is so that it can generate the proper code?

Solution
‎06-02-2014 01:42 PM
Super User
Super User
Posts: 7,076

Re: Annoying Note: Numeric values have been converted to character values at the places given by: (Line):(Column).

Here is code that does NOT depend on the type of the variable. Only conflict would be if the &RETAINV variable already existed in the data vector.

By making the first reference to the new &RETAINV variable an assignment statement SAS should automatically create it with the same type as the source variable.

%macro locf

(LOCFVar    /* Variable to retain */

,SortVar    /* By var */

,RetainV    /* Temporary variable to use for carry forward */

);

if first.&sortvar then &retainv = &locfvar ;

else if missing(&locfvar) then &locfvar = &retainv ;

else &retainv = &locfvar ;

retain &retainv ;

drop &retainv ;

%mend locf ;

Contributor
Posts: 35

Re: Annoying Note: Numeric values have been converted to character values at the places given by: (Line):(Column).

Lovely Tom! This solution removed all the annoying notes.  Your missing() suggestion is the KEY!  Thanks.

Contributor
Posts: 23

Re: Annoying Note: Numeric values have been converted to character values at the places given by: (Line):(Column).

From looking at your macro code, I suspect the issue is that, in one of the calls to the macro, the data type of RetainV does not match the data type of LOCFVar.

If no easier solution (such as rewriting the logic) presents itself, you could check the type of RetainV within your two main branches, and do explicit type conversions (with the INPUT or PUT functions) as necessary.

🔒 This topic is solved and locked.

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

Discussion stats
  • 10 replies
  • 1943 views
  • 0 likes
  • 6 in conversation