Just noticed this addition. It is a little quirky in that it does not return the current directory as the output of the function. Instead it writes a NOTE (or WARNING or ERROR) to the SAS log. The value returned is just a numeric status code with 0 meaning success. Also it does NOT have the problems some have mentioned in the comments. It will not change the current directory to a path that does not exist, in that case the current directory is left unchanged.

I have updated my 24 year old macro for that does return the current directory to also now allow you to change the current directory by adding an optional input argument. You can get the %CURDIR() macro from GITHUB, https://github.com/sasutils/macros/blob/master/curdir.sas