Q1
What is the subtle trap when using SAS MERGE without checking for duplicate BY-variable keys across BOTH datasets?
Unlike SQL JOIN (which performs a Cartesian product on many-to-many keys), SAS DATA step MERGE pairs rows sequentially one-for-one up to the longer group, silently misaligning unmatched records and issuing a MERGE statement has more than one data set with repeats of BY values note—always use PROC SQL for many-to-many joins.
Q2
Why does WHERE inside a SET step outperform subsetting IF inside a DATA step—and when can WHERE NOT be used?
WHERE filters rows inside the input buffer *before* SAS loads them into the Program Data Vector (PDV), cutting I/O heavily. However, WHERE cannot reference new variables created later in the DATA step or automatic _N_—requiring IF there.
Q3
What causes variables created inside a SAS DATA step to unexpectedly keep previous row values without RETAIN—when using SUM statement total + amount?
Normal assignment total = total + amount; resets total to missing . at the top of every iteration unless RETAIN is declared—AND propagates missing if amount is .. The sum statement total + amount; implicitly retains total initialized at 0 AND treats missing amount as 0!
Q4
In clinical/enterprise SAS, why does MISSING (.) evaluate as LESS THAN every negative number (-999999)?
SAS stores numeric missing values (., ._, .A–.Z) as the lowest possible numbers on the sort scale! Writing IF age < 18 THEN group = 'Child'; classifies missing ages as 'Child' unless you explicitly guard IF 0 <= age < 18 or NOT MISSING(age).
Q5
What is the difference between CALL SYMPUT / CALL SYMPUTX—and why do macro quotes/whitespace break &var comparisons?
CALL SYMPUT preserves leading/trailing formatted blanks (' 42'), breaking string equality or dynamic filenames. CALL SYMPUTX strips leading/trailing spaces automatically.
Q6
Why does resolving macro variable &&var&i require two ampersands (&&) inside SAS macro loops?
The macro processor scans left-to-right per pass: && resolves to one & while &i resolves to 1 on pass 1 (&var1), then pass 2 resolves &var1 to its actual stored value.
Q7
How do FIRST.var and LAST.var work—and why does forgetting BY sorting crash them?
FIRST. and LAST. flags (1 or 0) only exist when BY processing runs, which requires datasets to be pre-sorted (or indexed) in ascending/descending order—otherwise SAS throws a sorting runtime error.
Q8
Why is LENGTH var $ 50; BEFORE the SET statement critical when concatenating or altering existing character columns?
SAS fixes a variable's byte length the *very first time* the compiler sees it during compilation. If SET reads a 10-byte column first, assigning a 30-character string later silently truncates after 10 chars!
Q9
When summarizing datasets, why does PROC MEANS with NWAY prevent confusing extra rollup rows?
By default, PROC MEANS outputs every combination of CLASS margins (_TYPE_ = 0, 1, 2...). Adding NWAY restricts output strictly to the highest interaction level (_TYPE_ max).
Q10
In PROC SQL, why does omitting FEEDBACK hide wildcard expansions—and how do COALESCE + CALCULATED save intermediate passes?
CALCULATED alias lets SELECT or WHERE reuse a newly computed column alias cleanly inside the exact same PROC SQL query instead of repeating formulas or subqueries.