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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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;

View solution in original post

2 REPLIES 2
Astounding
PROC Star

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;

yahoo0806
Calcite | Level 5

It worked! Many thanks! There are still a lot of things I need to explore and learn for SAS macro 🙂

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1223 views
  • 0 likes
  • 2 in conversation