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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

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.

shonn2nd
Fluorite | Level 6

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.

Kurt_Bremser
Super User
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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 3 replies
  • 1046 views
  • 3 likes
  • 2 in conversation