I just looked at some code I had written a few months ago. It categorized things based on a bunch of criteria. At the end of the data step I output the categories that did not fit into a definition bucket nicely:
if bucket in(12,11,10,7,6,5,4) then output junk;
But then I remembered that I also wanted to see if any of them went past all the logic and came up with a missing bucket:
if bucket in(12,11,10,7,6,5,4.) then output junk;
Of course, YOU can see that I forgot the last comma between the 4 and . So missings weren't actually included. I didn't actually see it till today. Doh!
Tuesday, December 20, 2011
Fat Fingers
Subscribe to:
Post Comments (Atom)
I hate when that happens...
ReplyDeleteIn this sort of case, it's the one time when I fell good about using an open-ended else statement.
data new
junk
;
set old;
if bucket IN (1,2,3,8) then output new;
else output junk;
run;
I try to put an open-ended else on almost every if-then series (or select) just to make sure I'm not losing any data, e.g.:
data new;
set old;
if sex='M' then gender='Male';
else if sex='F' then gender='Female'
else put "ER" "ROR: unknown sex " sex=;
run;
Here's my only lame tip ... I always put the missing item first so I know I have it.
ReplyDeleteHey I recently discovered the missing function so you could also do ....
if bucket in (12, 11 )
or missing(bucket)
This makes me think of the saying "Experience is what you get, when you don't get what you want."