I guess I should add that maybe what I'm looking for is what is the minimum amount of the wrapper code that you need to keep when you try to take the generated code and then place it in a macro in a code block
Are you using the code from an Import Data task? If so, it generates these temporary #LN filename references, that only exist while the EG session is open. When you exit EG the reference is lost.
I would suggest that above the code for the import data task you add a file reference:
filename myfile "path-to-your-file";
Then in the import data task code, replace "#LN00017" with "myfile" and try it again.
There's an added complication if you're sas server is a unix server... if the path to your file is not visible from the server this won't work, but I think if you have sas on a windows server it should.