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

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???

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

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;
ballardw
Super User

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.

RorschachYoung
Fluorite | Level 6
i need to reuse this macro code several times, and i want to add some conditional control

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 513 views
  • 0 likes
  • 3 in conversation