Hello,
I am working through SAS EG 7, trying to bring in a list of filenames and associated details from an FTP directory. The following code brings in the filnmes (all are excel) but I'd like to bring in modified date as seen in windows explorer as well. the end goal is to produce a recurring dataset with only filenames newly added.
data all_files;
infile ftp_dir;
input;
file_name = _INFILE_;
file_path = strip(file_name);
if find(file_name,".xlsx") > 0 and find(file_name,"~") = 0;
run;
as a tangent question... is it possible to import folder names to create literal file_paths from the directory?
Thanks for any and all suggestions.
Function finfo() with information-item=1 returns the full file path. You can parse that string any way you like.
> I'd like to bring in modified date
Look at the foptnum, foptname and finfo functions.
I doubt they return anything with FTP but who knows. I am curious now.
> is it possible to import folder names to create literal file_paths from the directory?
Unsure what this means
Function finfo() with information-item=1 returns the full file path. You can parse that string any way you like.
Would you mind detailing here what the FTP filename returns for the different values of information-item ?
Maybe run this:
filename FREF ftp ... ;
%macro test;
%let fid=%sysfunc(fopen(FREF));
%let infonum=%sysfunc(foptnum(&fid));
%do j=1 %to &infonum;
%let name=%sysfunc(foptname(&fid, &j));
%let value=%sysfunc(finfo(&fid, &name));
%put File attribute &name equals &value;
%end;
%let rc=%sysfunc(fclose(&fid));
%let rc=%sysfunc(filename(filrf));
%mend test;
%test
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.