In a SAS session for VS Code, the value of the _SASFILEPATH macro variable is automatically set when you run code from a saved program file. You can extract the path portion of a fully qualified Windows file name like this:
%let filepath=%qsubstr(%superq(_SASPROGRAMFILE),1,%sysevalf(%sysfunc(find(%superq(_SASPROGRAMFILE),\,-99999))-1));
This part of the code reads backward from the end of the string, and finds the location of the first '\' character:
%sysfunc(find(%superq(_SASPROGRAMFILE),\,-99999))
The next portion takes that value and subtracts 1:
%sysevalf(%sysfunc(find(%superq(_SASPROGRAMFILE),\,-99999))-1)
Now we know the location of the end of the path in the text, so we use %QSUBSTR to extract the text from position 1 to the calculated end position:
%qsubstr(%superq(_SASPROGRAMFILE),1,%sysevalf(%sysfunc(find(%superq(_SASPROGRAMFILE),\,-99999))-1))
We can execute a %PUT statement to see the value in the log:
%put NOTE: Path is %superq(filepath);
Which yields:
NOTE: Path is c:\Users\3sekk\Desktop\spring 25\stat 574\hw1STAT574S25\01