Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Windows Network
Drive/Unix/Mainframe)
Here's a macro that reads the filenames available at a particular directory on any FTP server (i.e. Windows Network
Drive/Unix/Mainframe)...
And then assign the physical location of these files to macrovariables fileloc and ftploc below….need to assign a name to
the output dataset name to the outputdsn macro variable…
The output dataset will have the filenames | Fileattributes | builddt (i.e. timestamp)
So here’s the macro…Try it out for your self….
data Ftpcredentials;
length host1 $ 20;
set UserPasswords;
host1=compress("'"||host||"'");
if host1="&HOST"; /*Proceed further only if the Host user/password combination is identified */
call symput("user",compress("'"||user||"'"));
call symput("pass",compress("'"||pass||"'"));
run;
%mend Ftpcredentials;
/*This Macro checks ALL the Server Locs and builds a SAS dataset with the filenames */
%macro ReadfilesfromDirectory(fileloc,ftploc,outputdsn);
/*MF PDS requires extra quotes for Directory eg. 'MainframeServer' */
if servertype="MF" then call symput(compress("srcdir"||cnt),compress('"'||"'"||sourcedir||"'"||'"'));
else if servertype="UX" then call symput(compress("srcdir"||cnt),compress("'"||sourcedir||"'"));
else if servertype="WN" then call symput(compress("srcdir"||cnt),trim(left(sourcedir)));
call symput(compress("servertype"||cnt),compress(servertype));
call symput(compress("host"||cnt),compress("'"||host||"'"));
run;
/* Use the Filename Pipe statement to return the listing of the directory */
FILENAME rootloc pipe "&dircmd1";
/*Execute the dir command and Put the results in a dataset filenames;*/
data filenames;
length filenm $ 200 cdir $ 800;
infile rootloc truncover;
input text $char1000.;
filenm=scan(text,-1,'\');
builddt=input(scan(text,1," "),MMDDYY10.);
cdir=substr(text,1,find(text,filenm)-2);
run;
%end;
/* if servertype is MF or UX */
%else %if %index(&ftp_locs,&&servertype&servcnt.) gt 0 %then
%do;
%put;%put -------------SEARCHING FOR FILES ON SERVER: &&host&servcnt. AT LOCATION
&&srcdir&servcnt.------------------------------;%put;
%Ftpcredentials(&ftploc,&&host&servcnt); *get the username and password combo for the
Host;
/* For every host location mentioned get the names of files that match our search str;*/
/* Use the Filename FTP statement to return the listing of the directory */
FILENAME fname FTP "" LIST HOST=&&host&servcnt. CD=&&srcdir&servcnt. user=&user
pass=&pass lrecl=32767 recfm=v debug;
%mend ReadfilesfromDirectory;
/* Location of the FTP usernames /passwords required to login to the servers mentioned above */
%let ftploc="C:\Documents and Settings\SASTechies\Desktop\ftpcredentials.xls";