<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Reading filenames from directory: change user for acces to other paths in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-filenames-from-directory-change-user-for-acces-to-other/m-p/226513#M40772</link>
    <description>&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best wishes&lt;/P&gt;
&lt;P&gt;Eva&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro find_files (p_startdir  = );


	data dirs_found (compress=no); 
		length Root $120.; 
		root = "&amp;amp;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 &amp;lt;= 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 &amp;gt; 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 "&amp;amp;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;
&amp;nbsp;&lt;/PRE&gt;</description>
    <pubDate>Wed, 18 Nov 2015 09:19:47 GMT</pubDate>
    <dc:creator>Eva</dc:creator>
    <dc:date>2015-11-18T09:19:47Z</dc:date>
    <item>
      <title>Reading filenames from directory: change user for acces to other paths</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-filenames-from-directory-change-user-for-acces-to-other/m-p/226508#M40769</link>
      <description>&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;change user&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2015 09:18:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-filenames-from-directory-change-user-for-acces-to-other/m-p/226508#M40769</guid>
      <dc:creator>Eva</dc:creator>
      <dc:date>2015-11-18T09:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: Reading filenames from directory: change user for acces to other paths</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-filenames-from-directory-change-user-for-acces-to-other/m-p/226513#M40772</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best wishes&lt;/P&gt;
&lt;P&gt;Eva&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro find_files (p_startdir  = );


	data dirs_found (compress=no); 
		length Root $120.; 
		root = "&amp;amp;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 &amp;lt;= 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 &amp;gt; 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 "&amp;amp;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;
&amp;nbsp;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Nov 2015 09:19:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-filenames-from-directory-change-user-for-acces-to-other/m-p/226513#M40772</guid>
      <dc:creator>Eva</dc:creator>
      <dc:date>2015-11-18T09:19:47Z</dc:date>
    </item>
  </channel>
</rss>

