BookmarkSubscribeRSS Feed
ohad_m
Calcite | Level 5

Hi, I try to create a function that receives as input a folder name on the computer and outputs a list of all the programs in SAS that are in the folder with information about them such as path, creation date, etc.

6 REPLIES 6
ohad_m
Calcite | Level 5
 

Hi,

 

Do you havw an example ? 

Kurt_Bremser
Super User

See this:

%let folder=/folders/myfolders;
%let outds=programs;

data &outds;
length dref fref $8 pname $200;
format timestamp e8601dt19. size comma10.;
did = filename(dref,"&folder.");
if did = 0
then do;
  did = dopen(dref);
  if did
  then do;
    do i = 1 to dnum(did);
      pname = dread(did,i);
      if upcase(scan(pname,-1,'.')) = "SAS"
      then do;
        pname = "&folder./" !! pname;
        fid = filename(fref,pname);
        if fid = 0
        then do;
          fid = fopen(fref);
          if fid
          then do;
            timestamp = input(finfo(fid,foptname(fid,5)),nldatm32.);
            size = input(finfo(fid,foptname(fid,6)),best.);
            fid = fclose(fid);
            output;
          end;
          else putlog "Could not open " pname;
          fid = filename(fref);
        end;
        else putlog "Could not assign filename for " pname;
      end;
    end;
    did = dclose(did);
  end;
  else putlog "Could not open directory";
  did = filename(dref);
end;
else putlog "Could not assign dref";
keep pname size timestamp;
run;

This code is tested on University Edition on my Mac.

If you are using a different environment (namely Windows), the option number in the FOPTNAME function will most probably be different.

Kurt_Bremser
Super User

PS the above is of course for those who do not enjoy the usage of external commands. With XCMD enabled, you just run ls (UNIX) or dir (Windows) with the correct parameters and read the output with FILENAME PIPE.

andreas_lds
Jade | Level 19

@ohad_m wrote:

Hi, I try to create a function that receives as input a folder name on the computer and outputs a list of all the programs in SAS that are in the folder with information about them such as path, creation date, etc.


Not clear what you want in the end, do you want to extract information visible to the operating system or do you want to extract information from the programs as well?

ohad_m
Calcite | Level 5

I want to create a function that receives as input the name of a folder on a computer and outputs the names of all SAS programs that exist within the folder, their path, size, and creation date

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 6 replies
  • 1237 views
  • 1 like
  • 3 in conversation