The first data step and the second do the same thing, but in different ways. When RENAME is used as a statement as in the first data step, the variable is renamed on the output dataset, but not in the statements in the data step. So, in data step 1, the gender variable is modified, and then renamed to "sex" on the output dataset. In the second data step, the gender variable is renamed when the data is read, so it is called "sex" in the data step, and in the output data.
RENAME used as a statement is non-executable, meaning that it does not matter where you put it in the code (unless you put it before the SET statement, in which case the RENAME statement will be the definition of the GENDER variable, meaning it will be numeric, and the code will generate an error).
In the third data step, the gender variable is renamed when the data is read, and then a new variable named "gender" is created. The new variable is only assigned a value when name='jack', and the sex variable (which was the original "gender" variable) is not modified.
Hope that answers your questions.
... View more