A SAS programmer writes: DATA output; SET input; IF _N_ = 1 THEN DO; ... END; RUN; What is the purpose of the IF _N_ = 1 condition?
Select an answer to reveal the explanation.
Short Explanation and Infographic
Here's the deal — b is correct because _N_ is a SAS automatic variable that counts the iteration of the DATA step loop — it equals 1 only on the first iteration when the first observation is being read. This is commonly used to initialize variables, open files, or execute setup logic exactly once.
Full explanation below image
Full Explanation
B is correct because _N_ is a SAS automatic variable that counts the iteration of the DATA step loop — it equals 1 only on the first iteration when the first observation is being read. This is commonly used to initialize variables, open files, or execute setup logic exactly once. A is wrong because _N_ counts iterations, not variables. C is wrong because _N_ is automatically incremented by SAS, not assigned by the programmer. D is wrong because the condition controls when the DO block executes, not which observations are output.