Hi all,
I recently wrote a SAS code as below.
The idea is if the &probf is => 0.1 then run the first model; if the &probf <0.1 then run the second model. This code runs fine however, when my &probf = 1.4513221E-6, it seems only run the first model regardless this probf value is actually less than 0.1.
Can you please let me know if you know why?
%if &probf >= 0.1 %then
%do;
ods output diffs=lsdiff LSMeans=lsm Tests3=Tests3;
proc mixed data=admmtt method=REML covtest alpha=0.05;
class usubjid trt01pn atptn siteid;
model aval= trt01pn atptn siteid trt01pn*atptn/htype=3 ddfm=KENWARDROGER;
repeated atptn/sub=usubjid type=&type1;
lsmeans atptn*trt01pn/pdiff cl alpha=0.05;
run;
%end;
%else %if 0 =< &probf < 0.1 %then
%do;
ods output diffs=lsdiff LSMeans=lsm Tests3=Tests3;
proc mixed data=admmtt method=REML covtest alpha=0.05;
class usubjid trt01pn atptn siteid;
model aval= trt01pn atptn siteid trt01pn*atptn trt01pn*siteid/htype=3 ddfm=KENWARDROGER;
repeated atptn/sub=usubjid type=&type1;
lsmeans atptn*trt01pn/pdiff cl alpha=0.05;
run;
%end;
The fact that the top half runs fine is a lucky accident. Macro language is treating &PROBF as a character string and comparing it to the character string "0.1". To make a numeric comparison, use:
%if %sysevalf(&probf >= 0.1) %then %do;
For the bottom half, macro language does not process multiple comparisons the same way that a DATA step would. You will need to spell them out as two comparisons:
%else %if %sysevalf(0 <= &probf) and %sysevalf(&probf < 0.1) %then %do;
Technically, since you are using %else, you could eliminate the second comparison:
%else %if %sysevalf(0 <= &probf) %then %do;
The fact that the top half runs fine is a lucky accident. Macro language is treating &PROBF as a character string and comparing it to the character string "0.1". To make a numeric comparison, use:
%if %sysevalf(&probf >= 0.1) %then %do;
For the bottom half, macro language does not process multiple comparisons the same way that a DATA step would. You will need to spell them out as two comparisons:
%else %if %sysevalf(0 <= &probf) and %sysevalf(&probf < 0.1) %then %do;
Technically, since you are using %else, you could eliminate the second comparison:
%else %if %sysevalf(0 <= &probf) %then %do;
It worked! Many thanks! There are still a lot of things I need to explore and learn for SAS macro 🙂
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.