BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
hellind
Quartz | Level 8

 

 

%macro misrewrite2( );
  
data rw_orig;
set rw1.rw&yymm.; 

day_new = 5;
cycle_new = .; 


if day_new gt cycle_new then result=1;
else result=2;


run;
  
%mend misrewrite2; 
%misrewrite2( );

Why does it return result=1 when I am expecting result=2?

 

A positive numeric value compared against a missing numeric value would return False.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

@hellind wrote:

Why does it return result=1 when I am expecting result=2?

 

A positive numeric value compared against a missing numeric value would return False.


Why would you think that?  That is not what your example shows.

It is also not what the documentation says.

Within SAS, a missing value for a numeric variable is smaller than all numbers.

Perhaps you are thinking of some other system that implement TRI level logic where the result of a boolean expression could be TRUE or FALSE or unknown.  But SAS only used BINARY logic.  Any boolean expression is either TRUE or FALSE.  And to make that possible all missing values are less than all non-missing value.  And missing values are treated as equal to the same missing value.

 

Try this experiment to see how SAS orders numbers.

data test;
  do i=-1,0,1,.,._,.a,.b,.y,.z;
    output;
  end;
run;
proc sort data=test; 
  by i;
run;
proc print;
run;

Results:

Spoiler
  Obs     i

   1      _
   2      .
   3      A
   4      B
   5      Y
   6      Z
   7     -1
   8      0
   9      1

 

 

View solution in original post

1 REPLY 1
Tom
Super User Tom
Super User

@hellind wrote:

Why does it return result=1 when I am expecting result=2?

 

A positive numeric value compared against a missing numeric value would return False.


Why would you think that?  That is not what your example shows.

It is also not what the documentation says.

Within SAS, a missing value for a numeric variable is smaller than all numbers.

Perhaps you are thinking of some other system that implement TRI level logic where the result of a boolean expression could be TRUE or FALSE or unknown.  But SAS only used BINARY logic.  Any boolean expression is either TRUE or FALSE.  And to make that possible all missing values are less than all non-missing value.  And missing values are treated as equal to the same missing value.

 

Try this experiment to see how SAS orders numbers.

data test;
  do i=-1,0,1,.,._,.a,.b,.y,.z;
    output;
  end;
run;
proc sort data=test; 
  by i;
run;
proc print;
run;

Results:

Spoiler
  Obs     i

   1      _
   2      .
   3      A
   4      B
   5      Y
   6      Z
   7     -1
   8      0
   9      1

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 72 views
  • 1 like
  • 2 in conversation