Only hold a lock for the absolute minimum amount of time required to perform the write operation. Never perform heavy calculations or network calls inside a locked block.
Sometimes, the "other thread" isn't yours at all. error resource is write-locked by another thread
The file is open in another program (like Microsoft Excel) or another SAS session. Only hold a lock for the absolute minimum