BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ksmit
Obsidian | Level 7

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

Function finfo() with information-item=1 returns the full file path. You can parse that string any way you like.

 

View solution in original post

5 REPLIES 5
ChrisNZ
Tourmaline | Level 20

> 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

Ksmit
Obsidian | Level 7
Thanks for the suggestion. Looking into those functions now.

Realted to the second ask. Was wondering if there was a function to write the file folder path as it appears in windows directory into sas data field. (i.e., c:\ my_folder\sub_folder\filename.xlsx would return a variable of my_folder\sub_folder\)

Thanks
ChrisNZ
Tourmaline | Level 20

Function finfo() with information-item=1 returns the full file path. You can parse that string any way you like.

 

Ksmit
Obsidian | Level 7
This got me there. Thanks Chris.
ChrisNZ
Tourmaline | Level 20

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 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 5 replies
  • 633 views
  • 0 likes
  • 2 in conversation