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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 542 views
  • 1 like
  • 3 in conversation