BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Abdu
Calcite | Level 5

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;

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

10 REPLIES 10
Reeza
Super User

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.

Abdu
Calcite | Level 5

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

Astounding
PROC Star

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. 

Abdu
Calcite | Level 5

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

ballardw
Super User

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.

Abdu
Calcite | Level 5

Hi Ballarsw,

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

Thanks,

Abdu

Tom
Super User Tom
Super User

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?

Tom
Super User Tom
Super User

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 ;

Abdu
Calcite | Level 5

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

MikeRhoads
Obsidian | Level 7

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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