I’ve just started learning SAS because I’m required to use it for a statistics course. For this course, the university provides SAS 9.2 through their virtual-machine setup: I make a reservation in their system, they generate a VM on one of their servers, and I connect to the VM using Microsoft’s Remote Desktop client. The virtual machines are generated and erased per session; settings are reset every time, and files must be stored on my client computer (which is accessible in the VM by a UNC path).
Within this setup, when I open a program file stored on my laptop, I’ve only been able to access the accompanying data files (each stored in the same folder as the program) either by hardcoding the full path or by updating the “current folder” setting at the beginning of each session. The first is problematic because it means the program won’t run anywhere else – in particular, when I email it to the professor. The second is inconvenient, because browsing to this particular UNC path is time consuming, and I already have to browse to the same path to open the program file.
I want to make this easier by programmatically setting the current folder to the folder containing the program. Then I could just open the file and get to work. I’ve found some examples of getting the filename of the program file, of getting the path to a fileref, and of (link limit exceeded) setting the current folder, but I haven’t been able to combine them in the right way. Please connect the dots for me.
Complete Answer:
SAS’s obtuse notation requires some strange delimiter fiddling to combine my partial solution (finding the path) with @Bob Duell’s partial solution (setting the current folder). There seem to be two key rules involved:
So the solution is to compute a string of the quoted path (where the quotes are part of the string), and expand that within a double-quoted parameter to X or SYSTEM:
It’s not required to store the string, both &src and &qsrc can be expanded in-place, which yields a single statement solution:
This executes correctly, but breaks the syntax coloring in the GUI. Within a string,
%str(%")and""both expand to", so replacing%str(%")with""both executes correctly and is colored correctly in the GUI:This inherits the limitation that it only works when SAS_EXECFILEPATH and SAS_EXECFILENAME are defined, which is the case when running from within the Windows GUI editor. It’s also subject to any limitations on in the “cd” command, which SAS intercepts rather than invoking the Windows command line. I expect it will fail on paths containing quotes.