Difference between IF and WHERE statement of output table

Accepted Solution Solved
Reply
Regular Contributor
Posts: 242
Accepted Solution

Difference between IF and WHERE statement of output table

The difference between IF and WHERE statment is - IF statement applies filter after reading data in PDV and where applies even before reading in PDV. 

 

Suppose where statement written in output dataset as shown below then what is the difference. 

 

data new_1 (where= (x=2));
input x;
t=x;
cards;
1
2
3
4
;


data new_2;
input x;
if x=2 ;
cards;
1
2
3
4
;


Accepted Solutions
Solution
‎06-15-2016 04:08 AM
Super User
Posts: 6,963

Re: Difference between IF and WHERE statement of output table

In your case, there is no difference.

But the subsetting if is part of data step logic and allows you to exit from a data step iteration prematurely; the where option in the output dataset does not influence data step logic, and therefore all data step iterations will be completed, even if semantically unnecessary.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
‎06-15-2016 04:08 AM
Super User
Posts: 6,963

Re: Difference between IF and WHERE statement of output table

In your case, there is no difference.

But the subsetting if is part of data step logic and allows you to exit from a data step iteration prematurely; the where option in the output dataset does not influence data step logic, and therefore all data step iterations will be completed, even if semantically unnecessary.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 204 views
  • 1 like
  • 2 in conversation