...
change user
Dear all,
I read filenames from a given Directory (path) which works well. Now I'd like to read the filenames from a Directory to which I have no Access, but a technical user has (I know userid and Password).
My question is: how can I use this userid in the code?, i.e. Change the user to read the filenames? Please see code below.
Best wishes
Eva
%macro find_files (p_startdir = ); data dirs_found (compress=no); length Root $120.; root = "&p_startdir."; output; run; /* Updated list of directories searched */ data dirs_found files_found (compress=no); /* Names of files found. */ keep Path FileName FileType; length fref $8 Filename $120 FileType $16; /* Read the name of a directory to search. */ modify dirs_found; /* Make a copy of the name, because we might reset root. */ Path = root; rc = filename(fref, path); if rc = 0 then do; did = dopen(fref); rc = filename(fref); end; else do; length msg $200.; msg = sysmsg(); putlog msg=; did = .; end; if did <= 0 then do; putlog 'ERR' 'OR: Unable to open ' Path=; return; end; dnum = dnum(did); do i = 1 to dnum; filename = dread(did, i); fid = mopen(did, filename); /* It's not explicitly documented, but the SAS online */ /* examples show that a return value of 0 from mopen */ /* means a directory name, and anything else means */ /* a file name. */ if fid > 0 then do; /* FileType is everything after the last dot. If */ /* no dot, then no extension. */ FileType = prxchange('s/.*\.{1,1}(.*)/$1/', 1, filename); if filename = filetype then filetype = ' '; output files_found; end; else do; /* A directory name was found; calculate the complete */ /* path, and add it to the dirs_found data set, */ /* where it will be read in the next iteration of this */ /* data step. */ root = catt(path, "/", filename); output dirs_found; end; end; rc = dclose(did); run; data sas_progs_found (keep=filename); set files_found (where=(Filetype eq "sas")); filename_alt = filename; laenge = length(filename_alt); filename= "%" || substr(filename_alt,1, laenge-4); run; proc sort data=sas_progs_found nodupkey; by filename; run; %if "&p_DebugMode." eq "J" %then %do; title ****** Directories *******; proc print data=dirs_found; run; title ****** Files *******; proc print data=files_found; run; title ****** SAS-Programme *******; proc print data=sas_progs_found; run; title ; %end; %mend;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.