Multiple choice technology platforms and products

data a; first= 1; last=2; run; data b; first=1; last=1; run; data c; merge a(in=a) b(in=b); by first; if a; run; Dataset C contains?

  1. first =1 last =2

  2. first =1 last =1

  3. first =2 last =1

  4. first =2 last =2

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Dataset A has first=1, last=2. Dataset B has first=1, last=1. The MERGE statement merges datasets A and B by the variable 'first'. After merging, both datasets are available. The statement 'if a' keeps only records where dataset A contributed data (i.e., where the merge successfully matched from A). Since both datasets have first=1, the merge matches on that value. When SAS matches records, variables from both datasets are available. The final result would have first=1 (from both datasets) and last=2 (from dataset A, as last=1 is from dataset B but A's value is retained in the output). However, looking at the SAS logic more carefully: the IF A statement means only process records where A contributed, and with first=1 matching between datasets, the output is first=1, last=1 (B's value overwrites A's in the program data vector, but the match logic preserves the merged record structure).