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;
========================
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 ;
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.
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
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.
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
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.
Hi Ballarsw,
The program called this macro is little long. But I am posting the code entirely, if it helps.
Thanks,
Abdu
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?
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 ;
Lovely Tom! This solution removed all the annoying notes. Your missing() suggestion is the KEY! Thanks.
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.