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.
In a data step, use the following functions:
Hi,
Do you havw an example ?
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.
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.
@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?
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
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.
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.
Ready to level-up your skills? Choose your own adventure.