Are these folders on a disk? Or just in SAS Viya cloud storage?
If you can reference the folder directly in SAS code then it should be on an actual disk (or something that is behaving like an actual disk).
So you might try running code like this macro to get an idea of how many folders there are the directory tree.
https://github.com/sasutils/macros/blob/master/dirtree.sas
Note the macro will default to travelling down a maximum of 120 levels in the directory tree. It will also stop if the directory name would get longer then 256 bytes.
The usual cause of that type of infinite nesting is circular symbolic links. But I would be surprised if you could create symbolic links on SAS on Demand as it would normally require running an operating system command to make a symbolic link.