The SET statement is not just a label to identify the source of the data. Instead, it is an instruction to read in the next observation. The SET statement executes many times per DATA step, not just once. Each time it executes it reads in another observation.
The statements within the DATA step execute in order. So you need the SET statement to execute first, reading in an observation, and then the assignment statement for monthyear_var to execute next. After outputting the results, the DATA step continues. The SET statement reads in the next observation, the assignment statements computes another value, and the DATA step outputs the results. Eventually, the SET statement runs out of observations to read. When it fails to find another observation, the DATA step ends.
... View more