BookmarkSubscribeRSS Feed
AK100
Pyrite | Level 9

Is there a way to get the folder tree of my SASFolders in my command prompt? 

12 REPLIES 12
japelin
Rhodochrosite | Level 12

What exactly does SASFolders indicate?
Folders that the library refers to?

What is the environment?
By command prompt, do you mean SAS for Windows?

Do you mean you want to get it in SAS, or just a pure command prompt, without starting SAS?

AK100
Pyrite | Level 9
With my SASFolders I literally mean all the SAS directories and files that I have. The environment is Windows. I just want the whole file tree weather that's in the windows command prompt or in SAS Enterprise guide.
Kurt_Bremser
Super User

Be careful with your wording. SASFolders is usually associated with the internal folder structure of SAS metadata ("Folders" in Management Console).

What you mean is the filesystem structure.

With Windows, I would use the dir command with the proper options in a FILENAME PIPE and read the results with a data step.

If XCMD is not enabled, here's a piece of code by @Tom that recursively reads a directory tree with pure SAS means:

data filelist;
  length dname filename $256 dir level 8 lastmod size 8;
  format lastmod datetime20.;
  input dname;
  retain filename ' ' level 0 dir 1;
cards4;
/folders/myfolders
;;;;

data filelist;
  modify filelist;
  rc1=filename('tmp',catx('/',dname,filename));
  rc2=dopen('tmp');
  dir = not not rc2;
  if not dir then do;
    fid=fopen('tmp','i',0,'b');
    lastmod=input(finfo(fid,foptname(fid,5)),NLDATM100.);
    size=input(finfo(fid,foptname(fid,6)),32.);
    fid=fclose(fid);
  end;
  else do;
    dname=catx('/',dname,filename);
    filename=' ';
    lastmod=input(dinfo(rc2,doptname(rc2,5)),NLDATM100.);
  end;
  replace;
  if dir;
  level=level+1;
  do i=1 to dnum(rc2);
    filename=dread(rc2,i);
    output;
  end;
  rc3=dclose(rc2);
run;
AK100
Pyrite | Level 9
you have folders/myfolders. What should I do to find my folders?
Kurt_Bremser
Super User

Insert the path(s) to be searched in the datalines.

The code as posted is for demonstration purposes so that it works in University Edition, but it can be applied to any environment that runs on a hierarchical filesystem (UNIX and Windows).

AK100
Pyrite | Level 9
Well I need to know where my files resist. Is there a short way to check that?
ballardw
Super User

@AK100 wrote:
Well I need to know where my files resist. Is there a short way to check that?

Which files?

Data sets?

Programs?

Macros?

Reports?

Templates?

Options?

SAS Executable?

SAS Configuration?

 

Lots of different types of files and some of these are easy to get to in the metadata SAS maintains and others require using operating system tools. Specificity in need leads to better targeted responses.

Kurt_Bremser
Super User

@AK100 wrote:
Well I need to know where my files resist. Is there a short way to check that?

Most of your files will be on your harddisk.

 

Spoiler
This is the kind of answer this kind of question usually gets. Please be more specific what you are looking for. Also see Maxim 42.
japelin
Rhodochrosite | Level 12

The following code is a quick example.

cd "C:\Program Files\SASHome2"

rem all sasfiles
dir /s /b | findstr /i /R "\.sas" >c:\temp\sasdir.txt rem all directories and sasfiles tree /f | findstr /I /R "─ \.sas" >c:\temp\sastree.txt
AK100
Pyrite | Level 9
Where do you want me to run this code? In the windows cmd? Or open a program file in Enterprise Guide?
japelin
Rhodochrosite | Level 12

That is for command prompt.

So save as .cmd or .bat and double click to start.

AK100
Pyrite | Level 9
What do you mean?

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 12 replies
  • 2917 views
  • 1 like
  • 4 in conversation