SAS macro if then else always ELSE

During making some heatmap I face with some problem. All my cells is painting with yellow! MLOGIC show that all the statements TRUE with yellow colour but the values in cells is a different? there is all red and white. Could you tell me my mistake& Thank you! The code and log below:

%macro main;

ods html body='temp.html';

proc report data=step3 nowd;
column  kri_id range_mid_1 range_mid_2 
%do i=1 %to 9;
a2017_M0&i. %end;
;
define kri_id / display;
define range_mid_1 / display;
define range_mid_2 / display;
%do i=1 %to 9;
define a2017_M0&i. / display;
%end;
%do p=1 %to 9;
compute a2017_M0&p.;
     %if a2017_M0&p. > range_mid_2
     %then call define(_col_, "style", "STYLE=[background=red]");

%else %if  range_mid_1 < a2017_M0&p. < range_mid_2
     %then call define(_col_, "style", "STYLE=[background=yellow]");
     ;endcomp;
%end;
;run;

ods html close;
ods html body='temp.html';
%mend; %main;

Log file is bellow

SYMBOLGEN:  Macro variable P resolves to 1
MLOGIC(MAIN):  %IF condition a2017_M0&p. > range_mid_2 is FALSE
SYMBOLGEN:  Macro variable P resolves to 1
MLOGIC(MAIN):  %IF condition range_mid_1 < a2017_M0&p. < range_mid_2 is TRUE
MPRINT(MAIN):   call define(_col_, "style", "STYLE=[background=yellow]") ;
MPRINT(MAIN):  endcomp;
MLOGIC(MAIN):  %DO loop index variable P is now 2; loop will iterate again.
SYMBOLGEN:  Macro variable P resolves to 2
MPRINT(MAIN):   compute a2017_M02;
SYMBOLGEN:  Macro variable P resolves to 2
MLOGIC(MAIN):  %IF condition a2017_M0&p. > range_mid_2 is FALSE
SYMBOLGEN:  Macro variable P resolves to 2
MLOGIC(MAIN):  %IF condition range_mid_1 < a2017_M0&p. < range_mid_2 is TRUE
MPRINT(MAIN):   call define(_col_, "style", "STYLE=[background=yellow]") ;
MPRINT(MAIN):  endcomp;
MLOGIC(MAIN):  %DO loop index variable P is now 3; loop will iterate again.
SYMBOLGEN:  Macro variable P resolves to 3
MPRINT(MAIN):   compute a2017_M03;
SYMBOLGEN:  Macro variable P resolves to 3
MLOGIC(MAIN):  %IF condition a2017_M0&p. > range_mid_2 is FALSE
SYMBOLGEN:  Macro variable P resolves to 3

And ETC

Upvotes: 0

Views: 437

Answers (2)

Thank you! With your help I found the answer here. I had to use IF THE ELSE without %. Than it compares the variables

Upvotes: 0

Tom
Tom

Reputation: 51566

You are using macro logic where you want actual SAS code logic.

The reason you are always getting the %ELSE clause is because the letter a is less than the letter r so this test is always false.

%if a2017_M0&p. > range_mid_2

To the macro processor a2017_M01 and range_mid_2 are just text strings. The macro processor knows nothing of your data set variables.

Upvotes: 2

Related Questions