Desktop productivity for business analysts and programmers

Read Files in A Directory

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

Read Files in A Directory

Hello Community,

Environment:

Enterprise Guide on UNIX via CITRIX over a Windows XP PC.

Situation:

I have serveral .CSV files located in /aaa/bbb/ccc/ddd

Now i would like to read all CSV files from this folder into a SAS table.

I only want to read the FILENAMES not the content.

I cant use "call system" or "filename x pile ..:" Statements. (Permissions)

I found another option by using the dopen() function.

When i try to open my file the dopenfunction returns a zero (file not found)

In the LOG  all files are accessed (see LOG)

Question:

I dont know what am I doing wrong? (im not having so much experience)

but why cant dopen open the directory and output my files.

Sourcecode

%let path = /aaa/bbb/ccc/ddd;

filename dir "&path/*";

data content;

    did=dopen("dir");

   if did eq 0 then do;

    infile dir length=linelen;

        input dir $Varying200. linelen;

   end;

   else do;

     msg=sysmsg();

      put msg;

   end;

run;

filename dir clear;

LOG:

NOTE: The infile DIR is:

      Filename=/aaa/bbb/ccc/ddd/2013-12-06-A.CSV,

      File List=/aaa/bbb/ccc/ddd/*,

    

NOTE: The infile DIR is:

      Filename=/aaa/bbb/ccc/ddd/2013-12-06-B.CSV,

      File List=/aaa/bbb/ccc/ddd/*,

 

NOTE: The infile DIR is:

      Filename=/aaa/bbb/ccc/ddd/2014-03-18-B.CSV,

      File List=/aaa/bbb/ccc/ddd/*,

 

NOTE: The infile DIR is:

      Filename=/aaa/bbb/ccc/ddd/2014-03-19-A.CSV,

      File List=/aaa/bbb/ccc/ddd/*,

    

WANT:

I want exactly this: 2013-12-06-A.CSV or the whole path /aaa/bbb/ccc/ddd/2014-03-19-A.CSV

in my table

can someone help me? I'm desperate...

Thanks


Accepted Solutions
Solution
‎04-02-2014 12:46 PM
Super User
Super User
Posts: 6,851

Re: Read Files in A Directory


All Replies
Trusted Advisor
Posts: 3,208

Re: Read Files in A Directory

did you follow the example as of: SAS(R) 9.4 Functions and CALL Routines: Reference, Second Edition ?

It is the doptname function retrieving the information not the input statement.

What you have shown with the input statement is that a directory (with HFS as Unix/Windows)  is nothing more as a dataset. That dataset (directory) is having a list of pointers to ....

It is shamefull not having the OS layers for security in place as you can do everything with SAS. Oh they will try to block that also.

More easier would be allowing the x-cmd by you platform admin. When he did his work well putting you in an isolated secured box  sandbox. There is no security issue involved.

It is something like following the dogtail someone started it claiming it could be harmfull and without verifying understanding many followers. 

---->-- ja karman --<-----
Solution
‎04-02-2014 12:46 PM
Super User
Super User
Posts: 6,851

Re: Read Files in A Directory

Trusted Advisor
Posts: 3,208

Re: Read Files in A Directory

Yes that is the one for the members with example

---->-- ja karman --<-----
Occasional Contributor
Posts: 12

Re: Read Files in A Directory

@Jaap Karmann

I totally agree with you...even  in a test envirnonment our permissions are restricted to nothing *laught

@Both

Thanks for the help it works Smiley Happy

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 1330 views
  • 7 likes
  • 3 in conversation