As the first step in the decommissioning of the site has been converted to read-only mode.

Here are some tips for How to share your SAS knowledge with your professional network.

WHERE vs IF Statements

From sasCommunity
Revision as of 11:55, 27 October 2017 by Paulkaefer (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


WHERE vs. IF Statements: Knowing the Difference in How and When to Apply

View Presentation Now: WHERE vs. IF Statements [1]


Sunil Gupta,

- CDISC for Medical Device Team (Industry Expert)

- Subject Matter Expert for Edit Check Design Principles Chapter in Good Clinical Data Management Practices (GCDMP)

- E-mail Sunil to be included on his e-mail distribution list

More classes, articles and books by Sunil Gupta.

SAS User Quote

"The first paper I read from you was " When do I use a WHERE statement vs. an IF statement to subset a data set?" That paper clarified my understanding to differentiate two terms and helped solve the problem at work. All the papers written by you are very helpful and easy to understand. Thank you and Keep up the good work."

Leena Vaidya, SAS Programmer at New York University

"Actually I read few of your papers, they were very informative and cleared many doubts, especially one with the where and if statement usage then I visited your website which was very helpful for references."

Sonal Gupta, SAS Programmer


When programming in SAS, there is almost always more than one way to accomplish a task. Beginning programmers may think that there is no difference between using the WHERE statement and the IF statement to subset your data set. Knowledgeable programmers know that depending on the situation, sometimes one statement is more appropriate than the other. For example, if your subset condition includes automatic variables or new variables created within the DATA step, then you must use the IF statement instead of the WHERE statement. This paper shows you how and when to apply the WHERE and IF statements to get correct and reliable results. It also reviews the similarities as well as the differences between these two SAS programming approaches. Note that this paper does not focus on comparing the performance differences between the WHERE and IF statements.

Download Summary Sheet, SAS Paper and Technical Tip

Paper (PDF)

Summary Sheet (DOC)

WHERE vs. IF Statements: Knowing the Difference in How and When to Apply (SAS Usage Note 24286).

- Download all Sunil Gupta's SAS conference papers, presentations and hands-on workshops [2]

More information on Sharpening Your SAS Skills.

External links