As for the second part, you use the file statement, but never associated it with a file name. Was that intentional. Then, at the end, you close ods xml, but never opened it. Aren't you just trying to write a text file with an xml extension?

Write XML according data step

You haven't responded to my earlier questions, but I just noticed something else that you will have to change. Within the same datastep you use %let to assign a value to a macro variable and then try to use that macro variable within the same datastep. That won't work! You will have to move the %let statement outside of the datastep.