Using filename pipe (instead of the X command, or call execute) is a great way to submit OS commands, not least because the standard output can be read directly into SAS.

But how does one submit multiple commands in the same filename (or file) statement?

Easy – & I’ll show you how:

  data _null_;
    infile “D: & cd “”%sysfunc(pathname(work))”” & dir” pipe;

The above snippet opens a shell (via the pipe fileref), changes the working directory to the D drive, then to the work folder (our work location is on a different drive), then executed the dir command to demonstrate that we are indeed in the work folder.

The delimiter is, of course, the ampersand (&).