%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.
@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:
Obs i 1 _ 2 . 3 A 4 B 5 Y 6 Z 7 -1 8 0 9 1
@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:
Obs i 1 _ 2 . 3 A 4 B 5 Y 6 Z 7 -1 8 0 9 1
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.