Piping directory data from a UNC

Reply
Contributor
Posts: 20

Piping directory data from a UNC

I've been using information from some very useful papers to pipe in Windows directory information and take conditional actions against files in the directory. However, all of the examples I've found in SAS papers have used mapped drives rather than UNC locations. For my purposes, the latter would be preferable.

I'm executing the following code:

%let locstart=B:\Current\ESS;

OPTIONS NOXWAIT;

DATA _NULL_;

  Filename pipedir pipe "DIR &LOCSTART./S " ;

RUN;

DATA folderlist;

  Infile pipedir truncover;

  Input folerlist $char1000.;

  Length folder file $400 extension $5 date 8;

  Retain folder;

  If Index(folderlist,'Directory')>0 Then folder=Substr(folderlist,14,180);

  If Scan(folderlist,,'.') NE ' ' Then Do;

     file=Strip(Substr(folderlist,40,160));

     filename=Upcase(Scan(Strip(file),1,'.'));

     extension=Upcase(Scan(Strip(file),-1,'.'));

     date=MDY(Input(Substr(folderlist,1,2),8.),Input(Substr(folderlist,4,2),8.)

               ,Input(Substr(folderlist,7,4),8.));

  End;

  If date NE .;

  If Findc(extension,'~%%$')=0;

Run;

When "locstart" is set a shown (i.e., defined to "B:"), the code works fine. When instead I set

%let locstart=\\WCBData\EDGE\Current\ESS;

(the same location) and run the code, I get the message "Stderr output: The network name cannot be found." and the data is not read.

Is it possible to pipe directory information from a UNC description?

Super User
Posts: 3,252

Re: Piping directory data from a UNC

In theory there should be no difference. What happens if you try to define a LIBNAME with the UNC? We use UNC's exclusively for our LIBNAMEs etc and have no problems. The question - is the UNC known on the computer where you are running SAS?

Contributor
Posts: 20

Re: Piping directory data from a UNC

A libname statement works fine, as in

     libname bob '\\WCBData\EDGE Statements\Current\ESS';

     data bob.nada;

          input one two;

          cards;

          1 2

          3 4

          5 6

          ;

     run;

(I had incorrectly entered the share name in my initial post). However, I get the "network name cannot be found" message whether I enter the macro assignment in quotes or not. I also get the error when entering the location directly into the "filename" statement rather than through a macro variable:

DATA _null_;

     filename pipedir pipe "dir \\WCBData\EDGE Statements\Current\ESS/s " ;

RUN;

while

DATA _null_;

     filename pipedir pipe "dir B:\Current\ESS/s " ;

RUN;

works fine.

Super User
Super User
Posts: 7,039

Re: Piping directory data from a UNC

You do NOT need to wrap a FILENAME statement inside of an extraneous data _null_.

Looks like a quoting issue since your path includes embedded spaces.

filename pipedir pipe "dir ""\\WCBData\EDGE Statements\Current\ESS"" /s" ;

Or you can use the command directly in the INFILE statement without creating a fileref.

DATA files ;

     infile "dir ""\\WCBData\EDGE Statements\Current\ESS"" /s" pipe ;

  ...

RUN;

or you can use the QUOTE() function to make sure that inner quotes are doubled.

%let path=\\WCBData\EDGE Statements\Current\ESS ;

DATA _null_;

     infile %sysfunc(quote(dir "&path" /s)) pipe ;

RUN;

Message was edited by: Tom Abernathy

Corrected syntax to show that PIPE "engine" comes before the command string in the FILENAME statement, but after the command string in the INFILE statement.

Contributor
Posts: 20

Re: Piping directory data from a UNC

You may be correct that the problem is to do with the embedded space, but the solution doesn't work. First, it's necessary to remove the "pipe" suffix in your example (it gives an "invalid option name pipe" error). Taking the simplest case,

DATA _null_;

     filename pipedir "dir ""\\WCBData\EDGE Statements\Current\ESS"" /s" ;

RUN;

returns the error, "Invalid physical name. Error in the FILENAME statement." The same error is returned by

DATA _null_;

     filename pipedir "dir ""B:\Current\ESS"" /s" ;

RUN;

so the problem is now the embedded quotation marks in the call to DIR.

I also tried

DATA _null_;

     filename pipedir 'dir "\\WCBData\EDGE Statements\Current\ESS" /s' ;

RUN;

and some other variants with double quotes in the macro assignment, but no luck.

Super User
Posts: 11,343

Re: Piping directory data from a UNC

Have you found a version of syntax that works from a command prompt to give the results you're looking for?

Contributor
Posts: 20

Re: Piping directory data from a UNC

dir "\\wcbdata\edge statements\current\ess"/s

Super User
Super User
Posts: 7,039

Re: Piping directory data from a UNC

Corrected above, I was confused because you used a FILENAME statement placed inside of a DATA step.  The PIPE "engine" must be specified first in a FILENAME statement, but second in an INFILE statement.

Trusted Advisor
Posts: 3,212

Re: Piping directory data from a UNC

@Gticker you are asking an OoperatingSystem command the dir statement. You will need to have the pipe option in your statement for that.

You last statement in the dos-box is using the double quotes. All that arrounde with single qoutes (last try) and the pipe option should work.

The pipe option as in the examples  SAS(R) 9.4 Companion for Windows (Using Unnamed Pipes)

---->-- ja karman --<-----
Contributor
Posts: 20

Re: Piping directory data from a UNC

Do you have an example? Statements that don't work:

filename pipedir "dir '\\WCBData\EDGE Statements\Current\ESS' /s"; (response "physical file does not exist, C:\Users\e970275\dir '\\WCBData\EDGE Statements\Current\ESS'

filename pipedir 'dir \\WCBData\EDGE Statements\Current\ESS /s'; ("filename" fails; error "invalid physical name")

Trusted Advisor
Posts: 3,212

Re: Piping directory data from a UNC

FILENAME fileref PIPE                     'program-name' option-list;

filename pipedir 'dir '\\WCBData\EDGE Statements\Current\ESS /s';

"filename" fails; error "invalid physical name")'     yes errormessage is correct the file "dir '\\WCBData\EDGE Statements\Current\ESS /s"  does not exit .

I have never seen a file like that.  files like "B:\foo.txt" but not   "dir B:\foo.txt" as "dir "not being a file.    

filename pipedir PIPE "dir '\\WCBData\EDGE Statements\Current\ESS /s' "; 

/* Should execute the program "dir " with some params. That is the PIPE telling to change the function there

/* followed by:

DATA work._null_;

infile pipedir ; input ; put _infile_ ;

run;

/* should run the program (X processing allowed is required) listing the output of the program  */
/* in the earlier given link you could find then default file-numbers 1,2, so you could also redirect error messages */

  

---->-- ja karman --<-----
Contributor
Posts: 20

Re: Piping directory data from a UNC

Thanks very much for trying to help, but

DATA _null_;

  filename pipedir PIPE "dir '\\WCBData\EDGE Statements\Current\ESS /s' ";

run;

DATA work._null_;

infile pipedir ; input ; put _infile_ ;

run;

gives the error

 

NOTE: The infile PIPEDIR is:

Unnamed Pipe Access Device,

PROCESS=dir '\\WCBData\EDGE Statements\Current\ESS /s',

RECFM=V,LRECL=256

and

DATA _null_;

  filename pipedir PIPE "dir '\\WCBData\EDGE Statements\Current\ESS ' ";

run;

DATA work._null_;

infile pipedir ; input ; put _infile_ ;

run;

gives the error:

NOTE: The infile PIPEDIR is:

Unnamed Pipe Access Device,

PROCESS=dir '\\WCBData\EDGE Statements\Current\ESS ',

RECFM=V,LRECL=256

Stderr output:

The system cannot find the path specified.

Super User
Super User
Posts: 7,039

Re: Piping directory data from a UNC

Windows does not recognize the single quotes in:

   filename pipedir PIPE "dir '\\WCBData\EDGE Statements\Current\ESS /s' ";


It also will not like it that the /s option is included inside the quotes.


   filename pipedir PIPE "dir ""\\WCBData\EDGE Statements\Current\ESS"" /s";

Trusted Advisor
Posts: 3,212

Re: Piping directory data from a UNC

Ok tom,
I did the '  "  code on the wrong places.  As you stated Windows need the directory-filename to see with the double quotes ". Copied by hand and not checked carefully

The message is telling this now. It has executed the dir program, but that one has not the correct string.

The last steps are getting this right.

NOTE: The infile PIPEDIR is:

Unnamed Pipe Access Device,

PROCESS=dir '\\WCBData\EDGE Statements\Current\ESS ',

This is an example how something lookoing that easy could be get terribble by all interactions on meanings, ' " and macro quoting.

---->-- ja karman --<-----
Ask a Question
Discussion stats
  • 13 replies
  • 1423 views
  • 4 likes
  • 5 in conversation