<?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: Importing File name and Modified date into dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Importing-File-name-and-Modified-date-into-dataset/m-p/904625#M357395</link>
    <description>&lt;P&gt;That is a very valid observation, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;. I trust this code because I wrote and maintain it, but others should review before execution.&lt;/P&gt;
&lt;P&gt;I'll modify the solution to use PROC HTTP to first download the file, giving the user the opportunity to review the code before running it. Thanks for keeping me honest!&lt;/P&gt;
&lt;P&gt;Mark&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 27 Nov 2023 13:24:11 GMT</pubDate>
    <dc:creator>SASJedi</dc:creator>
    <dc:date>2023-11-27T13:24:11Z</dc:date>
    <item>
      <title>Importing File name and Modified date into dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-File-name-and-Modified-date-into-dataset/m-p/903637#M357055</link>
      <description>&lt;P&gt;I don't seem to be able to figure this out, but I'd like to pull into a dataset a listing of filenames and modification dates from a network folder.&amp;nbsp; I am thinking this is simple, but I don't seem be able find a solution that works.&amp;nbsp; Any thoughts would be appreciated.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2023 12:45:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-File-name-and-Modified-date-into-dataset/m-p/903637#M357055</guid>
      <dc:creator>Lost_Gary</dc:creator>
      <dc:date>2023-11-17T12:45:38Z</dc:date>
    </item>
    <item>
      <title>Re: Importing File name and Modified date into dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-File-name-and-Modified-date-into-dataset/m-p/903646#M357062</link>
      <description>&lt;P&gt;You can use the &lt;STRONG&gt;%findfiles&lt;/STRONG&gt; macro from my public&lt;A href="https://github.com/SASJedi/sas-macros" target="_self"&gt; GitHub sas-macros repository&lt;/A&gt; to do this pretty easily.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Get the macros straight from GitHub */ 
/* Supporting macro utilities */
filename attrib "fileattribs.sas";
filename exist "exist.sas";
filename trans "translate.sas";
/* The main FindFiles macro */
filename find "findfiles.sas";

proc http 
	url="https://raw.githubusercontent.com/SASJedi/sas-macros/master/findfiles.sas"
	out=find;
run;
proc http 
	url="https://raw.githubusercontent.com/SASJedi/sas-macros/master/exist.sas"
	out=exist;
run;
proc http 
	url="https://raw.githubusercontent.com/SASJedi/sas-macros/master/fileattribs.sas"
	out=attrib;
run;
proc http 
	url="https://raw.githubusercontent.com/SASJedi/sas-macros/master/translate.sas"
	out=trans;
run;
	 /* Review the contents of the macro programs before running them! */
data _null_;
	infile attrib;
	file print;
	input; 
	put _infile_;
run;
data _null_;
	infile exist;
	file print;
	input; 
	put _infile_;
run;
data _null_;
	infile trans;
	file print;
	input; 
	put _infile_;
run;
data _null_;
	infile find;
	file print;
	input; 
	put _infile_;
run;

/* Run the macro programs to compile the macros */
%include attrib;
%include exist;
%include trans;
%include find;

/* Get syntax help for FindFiles in the SAS log */
%FindFiles(?)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;From the log:&lt;/P&gt;
&lt;PRE&gt;NOTE:  *FINDFILES Documentation *******************************

       Produces a list of files with a specified extension in the log
       or optionally writes them to a dataset.

       SYNTAX: %FindFiles(dir,&amp;lt;ext,dsn,sub&amp;gt;)
          dir=fully qualified directory path
          ext=Space delimited list of file extensions (Optional, default is ALL)
          dsn=name of data set to store filenames (Optional, otherwise writes to log.)
          sub=look in subfolders? (Y|N default is Y)

       Example:
       %FindFiles(c:\temp, csv)
       %FindFiles(\\server\folder\, xls xlsx xlsm, work.myfiles)
       %FindFiles(s:/workshop,sas,work.pgm_files,N)

       *************************************************************
&lt;/PRE&gt;
&lt;P&gt;Now, use the macro to produce a dataset named &lt;STRONG&gt;work.files&lt;/STRONG&gt; containing information for all the files in \\localhost\c$\temp and all subfolders:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%FindFiles(\\localhost\c$\temp,,work.Files)
proc print data=work.files(obs=3);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;A sample of the results:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.FILES" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;Item&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;Path&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;Filename&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;Size&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;CRDate&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;CRTime&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;ModDate&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;ModTime&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;//localhost/c$/temp/subfolder&lt;/TD&gt;
&lt;TD class="l data"&gt;another_solution.sas&lt;/TD&gt;
&lt;TD class="r data"&gt;878&lt;/TD&gt;
&lt;TD class="r data"&gt;11/17/2023&lt;/TD&gt;
&lt;TD class="r data"&gt;8:43:59&lt;/TD&gt;
&lt;TD class="r data"&gt;11/10/2023&lt;/TD&gt;
&lt;TD class="r data"&gt;16:42:43&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;//localhost/c$/temp&lt;/TD&gt;
&lt;TD class="l data"&gt;have.csv&lt;/TD&gt;
&lt;TD class="r data"&gt;208&lt;/TD&gt;
&lt;TD class="r data"&gt;10/13/2023&lt;/TD&gt;
&lt;TD class="r data"&gt;8:29:05&lt;/TD&gt;
&lt;TD class="r data"&gt;10/13/2023&lt;/TD&gt;
&lt;TD class="r data"&gt;8:29:05&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="l data"&gt;//localhost/c$/temp&lt;/TD&gt;
&lt;TD class="l data"&gt;my.html&lt;/TD&gt;
&lt;TD class="r data"&gt;943&lt;/TD&gt;
&lt;TD class="r data"&gt;07/11/2023&lt;/TD&gt;
&lt;TD class="r data"&gt;16:38:10&lt;/TD&gt;
&lt;TD class="r data"&gt;07/11/2023&lt;/TD&gt;
&lt;TD class="r data"&gt;16:38:43&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May the SAS be with you!&lt;BR /&gt;Mark&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2023 13:40:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-File-name-and-Modified-date-into-dataset/m-p/903646#M357062</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2023-11-27T13:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: Importing File name and Modified date into dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-File-name-and-Modified-date-into-dataset/m-p/903737#M357082</link>
      <description>&lt;P&gt;Sorry, but I cannot seem to get that macro to work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am able to get this code to work, but only for the filename.&amp;nbsp; I am not exactly familiar with the loop and how to insert the date modified into this process.&amp;nbsp; Any thoughts are appreciated.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data filenames;&lt;BR /&gt;length fref $8 fname $200 ;&lt;BR /&gt;did = filename(fref,"\\My Folder");&lt;BR /&gt;did = dopen(fref);&lt;/P&gt;
&lt;P&gt;do i = 1 to dnum(did);&lt;BR /&gt;fname = dread(did,i);&lt;/P&gt;
&lt;P&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;did = dclose(did);&lt;BR /&gt;did = filename(fref);&lt;BR /&gt;keep fname;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2023 21:36:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-File-name-and-Modified-date-into-dataset/m-p/903737#M357082</guid>
      <dc:creator>Lost_Gary</dc:creator>
      <dc:date>2023-11-17T21:36:49Z</dc:date>
    </item>
    <item>
      <title>Re: Importing File name and Modified date into dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-File-name-and-Modified-date-into-dataset/m-p/903738#M357083</link>
      <description>&lt;P&gt;I think that macro is calling other macros. So you will need to download and compile those also.&lt;/P&gt;
&lt;P&gt;Or you could use this one which does not depend on other macros.&amp;nbsp;&lt;A href="https://github.com/sasutils/macros/blob/master/dirtree.sas" target="_blank"&gt;https://github.com/sasutils/macros/blob/master/dirtree.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Essentially you need to also use the FILENAME(), FOPEN(), FCLOSE() and FINFO() and perhaps FOPTNAME() functions to make a fileref pointing to each file and then open the file and retrieve information about the file, like the last modified date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the XCMD option is enabled you could also just use a PIPE and read the output of the DIR command.&lt;/P&gt;
&lt;P&gt;So something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile "dir \\My Folder" pipe truncover;
  input .... ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2023 23:03:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-File-name-and-Modified-date-into-dataset/m-p/903738#M357083</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-11-17T23:03:12Z</dc:date>
    </item>
    <item>
      <title>Re: Importing File name and Modified date into dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-File-name-and-Modified-date-into-dataset/m-p/903820#M357113</link>
      <description>&lt;P&gt;I think the following code is pretty dangerous:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Get the macro straight from GitHub */ 
filename code url "https://raw.githubusercontent.com/SASJedi/sas-macros/master/findfiles.sas";
%include code;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and should never be accepted in a serious working environment. I assume (but that is only an assumption) that you are a nice guy that would never put malicious code into your programs on github, but if you yourself are equally careless about running code that you have not even looked at, there is a serious risk that somebody else will hack your computer and plant malicious code in your programs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Imported code should be revisited before running, and should be copied to a local file to secure against unauthorized change.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Nov 2023 19:49:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-File-name-and-Modified-date-into-dataset/m-p/903820#M357113</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-11-19T19:49:37Z</dc:date>
    </item>
    <item>
      <title>Re: Importing File name and Modified date into dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-File-name-and-Modified-date-into-dataset/m-p/904625#M357395</link>
      <description>&lt;P&gt;That is a very valid observation, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;. I trust this code because I wrote and maintain it, but others should review before execution.&lt;/P&gt;
&lt;P&gt;I'll modify the solution to use PROC HTTP to first download the file, giving the user the opportunity to review the code before running it. Thanks for keeping me honest!&lt;/P&gt;
&lt;P&gt;Mark&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2023 13:24:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-File-name-and-Modified-date-into-dataset/m-p/904625#M357395</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2023-11-27T13:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: Importing File name and Modified date into dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-File-name-and-Modified-date-into-dataset/m-p/908921#M358598</link>
      <description>&lt;P&gt;This is what I was looking for:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/list-of-files-and-modified-date-in-a-dateset/m-p/667416#M199857" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/list-of-files-and-modified-date-in-a-dateset/m-p/667416#M199857&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 20:15:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-File-name-and-Modified-date-into-dataset/m-p/908921#M358598</guid>
      <dc:creator>Lost_Gary</dc:creator>
      <dc:date>2023-12-19T20:15:35Z</dc:date>
    </item>
  </channel>
</rss>

