The log should be pointing to this line for the error:
if last then do;
Firstly, code precedes the datalines statement.
Second the example uses the END= option for reading a dataset which is not available for DATALINES.
Example:
set Med_tmp end = last;
To use the End option first read the dataset and then use the code from the example on the SET statement reading the set just created.
Or read the data from an external file and use the End=last option on the INFILE statement.