BookmarkSubscribeRSS Feed
dgritt
Obsidian | Level 7

Since you can no longer use "." to implicitly reference the current working directory for batch grid jobs, try this:

%global pwd cwd;

%macro wd;
filename envcmd pipe 'set | egrep "PWD=|LS_SUBCWD="' lrecl=1024;

data env;
  length var $9 val $200;
  infile envcmd dlm='=' missover;
  input var $ val $;

  if val ^= ''
  then do;
    if var = 'PWD'
    then do;
      pwd = val;
      put pwd=;
      call symput('pwd',strip(val));
    end;

    if var = 'LS_SUBCWD'
    then do;
      cwd = val;
      put cwd=;
      call symput('cwd',strip(val));
    end;
  end;
run;

%if %superq(cwd) ^=
%then %let pwd = &cwd.;

%put pwd=&pwd.;

libname pwd "&pwd.";
libname here "&pwd.";
%mend wd;

%wd;

* End of Macro Include *;

Example output:

(batch grid launch from command-line with sasgsub)
CWD=/path/where/sas/code/resides
PWD=/sas/config/compute/Lev1/SASApp

(batch grid launch from EG with XCMD and sasgsub)
CWD=/path/to/EG/home/where/sas/code/resides
PWD=/sas/config/compute/Lev1/SASApp


(interactive grid launch from EG)
CWD=/path/to/UNIX/home
PWD=/sas/config/compute/Lev1/SASApp


In the first two cases, we want the value of CWD to overwrite PWD and be captured in a macro-variable for assigning librefs, filerefs, etc. For the third case, it's not really helpful as neither path makes sense for assignment. This is really designed for capturing paths in batch grid jobs where the current working directory changes.

 

2 REPLIES 2
ChrisHemedinger
Community Manager

In what context do those last two lines work?  In another macro somewhere?  Or is your entire example meant to be enclosed in a macro?

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
dgritt
Obsidian | Level 7

@ChrisHemedinger, I updated my original post that hopefully answers your questions. I'd also be happy to discuss this more at GF.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2145 views
  • 1 like
  • 2 in conversation