I am a little bit confused about the following code:
DATA myshortoutputfile;
SET myoutputfile;
casenum = _N_;
IF casenum IN ( 164, 47, 55, 68, 2, 52, 61, 10, 1, 169) EQ 0
THEN DELETE;
RUN;why do we need EQ 0 and THEN DELETE here? Isn't this code equal to:
data myshortoutputfile;
set myoutputfile;
casenum = _N_;
if casenum IN (164, 47, 55, 68, 2, 52, 61, 10, 1, 169);
run;Thanks.
Quick answer: not needed.
And yes, your second code is valid and much better (less code, and the condition is simple and obvious to understand). The first code is just an attempt to obfuscate something simple, and an example for bad coding.
Quick answer: not needed.
And yes, your second code is valid and much better (less code, and the condition is simple and obvious to understand). The first code is just an attempt to obfuscate something simple, and an example for bad coding.
Hi KurtBremser,
Could you briefly talk about the logic of that weird code? what does that mean: if casenum is equal to one of the list and equal to zero then that case will be deleted?
Thanks.
if casenum in (164,47,55,68,2,52,61,10,1,169) eq 0 then delete;
is equivalent to
if (casenum in (164,47,55,68,2,52,61,10,1,169)) = 0 then delete;
which translates to
"if the condition (casenum can be found in the list) is false, then remove the observation"
which is the negation form of
"if the condition is true, then keep the observation"
which would be (in code)
if (casenum in (164,47,55,68,2,52,61,10,1,169)) = 1 then output;
and that can be shortened to the subsetting if.
Nearly 200 sessions are now available on demand in the Innovate Hub.
Watch Now →SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.