🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 12-22-2021 12:06 AM
(2581 views)
I tried a data step with two where statements and realised that only the second where condition is affecting the output - see sample code below:
data result_2where_conditions;
set class_birthdate;
where Registration = 'C';
where Age = 12;
run;
Can somebody shed some light on why this happens?
Thanks heaps.
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Only one WHERE statement can take effect, the second overrides the first. Combine both conditions in one statement with AND.
4 REPLIES 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Only one WHERE statement can take effect, the second overrides the first. Combine both conditions in one statement with AND.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Alternatively, add the keyword SAME to the second WHERE statement:
where same and age=12;
where same and age=12;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
While this is valid and works, I would not even teach it, as sooner or later someone comes up with
where condition1;
/* 1000 lines of data step code */
where same and condition2;
/* another 1000 lines of data step code */
where same and condition3;
which is horrible to debug and maintain.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I agree, for simple sets of conditions. For complex sets of conditions, it can be easier to read the "same and" version.