This is the first log, it looks weird:
4671 %put &p_nor &ProbF;
2.78E-16 0.5349
4672 %MACRO a;
4673 %if &p_nor>2.78 and &ProbF>0.1 %then %do;
4674 %put &p_nor>0.1 and &ProbF>0.1;
4675 %end;
4676 %else %do;
4677 %put else;
4678 %end;
4679 %MEND;
4680 %a
2.78E-16>0.1 and 0.5349>0.1
and then i try this one:
4685 %put &p_nor &ProbF;
2.78E-16 0.5349
4686 %MACRO a;
4687 %if &p_nor>2.79 and &ProbF>0.1 %then %do;
4688 %put &p_nor>2.79 and &ProbF>0.1;
4689 %end;
4690 %else %do;
4691 %put else;
4692 %end;
4693 %MEND;
4694 %a
else
when i assign a scientific notation to a macro variable,it seems sas make the judgement by using the numeric part of the macro variable.
it shows that in sas macro 2.78E-16>0.1 and 2.78E-16<2.79.
how to make sas to make a right judgement???
In SAS macro code statements that use conditions (%IF %WHILE %UNTIL) use %EVAL() to evaluate the condition. %EVAL() can only do integer arithmetic so if text does not look like an integer it is treated as pure text.
Use %SYSEVALF() instead to handle floating point, including scientific notation and date/time literals.
%if %sysevalf(&p_nor>2.79 and &ProbF>0.1) %then %do;
In SAS macro code statements that use conditions (%IF %WHILE %UNTIL) use %EVAL() to evaluate the condition. %EVAL() can only do integer arithmetic so if text does not look like an integer it is treated as pure text.
Use %SYSEVALF() instead to handle floating point, including scientific notation and date/time literals.
%if %sysevalf(&p_nor>2.79 and &ProbF>0.1) %then %do;
Why is this needed in macro code?
Macro code is to generate code generally and the kind of things dealing with decimal values smack strongly of data manipulation is not what the macro code does, or at least seldom should be involved with.
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.