<?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: Populating data set from Filename dirlist pipe &amp;quot;find tmpFolder&amp;quot; in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Populating-data-set-from-Filename-dirlist-pipe-quot-find/m-p/369409#M88190</link>
    <description>&lt;P&gt;I think you're overcomplicating things:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input date :mmddyy8. time :time20. pathstr :$100.;
format
  date mmddyy8.
  time time11.2
  file_name $50.
;
file_name = scan(pathstr,-1,'/');
drop pathstr;
cards;
06/16/17 09:40:19.8344320410 /workspace/alphabuilder/data-jp/D160125.DB
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It presumes that nobody fucked up by putting blanks into filenames; if that is a possibility, the initial read for pathstr would have to be done with a fixed format from a given position.&lt;/P&gt;</description>
    <pubDate>Thu, 22 Jun 2017 08:18:28 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-06-22T08:18:28Z</dc:date>
    <item>
      <title>Populating data set from Filename dirlist pipe "find tmpFolder"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Populating-data-set-from-Filename-dirlist-pipe-quot-find/m-p/369368#M88172</link>
      <description>&lt;P&gt;&lt;STRONG&gt;I'm running in linux and I'm trying to parse a number of rows formatted as follows (file name and directory structure&amp;nbsp;will be&amp;nbsp;variable)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;06/16/17 09:40:19.8344320410 /workspace/alphabuilder/data-jp/D160125.DB&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The goal from this example is a data set where each record includes&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Date = 06/16/17&lt;/P&gt;&lt;P&gt;Time =09:40:19.83&amp;nbsp;&lt;/P&gt;&lt;P&gt;File = D160125.DB&lt;/P&gt;&lt;P&gt;Folder = /workspace/alphabuilder/data-jp/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Sas code&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Test varaibles*/&lt;/P&gt;&lt;P&gt;%let folder = /workspace/uat/card2/ai/x796785/V_drive/alphabuilder/data-jp/ ;&lt;BR /&gt;%let prefix = M ;&lt;BR /&gt;%let suffix = db ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Filename dirlist pipe "find &amp;amp;folder. -iname &amp;amp;prefix.*&amp;amp;suffix. -printf '%TD %TT %p\n'";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data &amp;amp;outlist (keep=folder filename date time);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;Infile dirlist end=last;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;format date mmddyy10. time time8.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;input;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;*Create the folder= file directory location;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;date = input(_infile_,mmddyy10.);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;time = input(substr(_infile_,10,18),time8.);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;filename = substr(_infile_,length(_infile_) - index(reverse(_infile_),"/") + 2,length(_infile_));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;folder = substr(_infile_,29,length(_infile_)- index(reverse(_infile_),"/") );&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;Run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My problem:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Folder&amp;nbsp;includes the&amp;nbsp;filename at the end&lt;/P&gt;&lt;P&gt;/workspace/alphabuilder/data-jp/D160125.DB&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I tried a number of variations including&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;folder = substr(_infile_,29,length(_infile_)-&amp;nbsp;5 );&lt;/P&gt;&lt;P&gt;folder = substr(_infile_,29,35 );&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm sure this is a rookie issue but I haven't been able to google a solution.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2017 23:29:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Populating-data-set-from-Filename-dirlist-pipe-quot-find/m-p/369368#M88172</guid>
      <dc:creator>RichM</dc:creator>
      <dc:date>2017-06-21T23:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: Populating data set from Filename dirlist pipe "find tmpFolder"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Populating-data-set-from-Filename-dirlist-pipe-quot-find/m-p/369369#M88173</link>
      <description>&lt;P&gt;Assuming I correctly understand what you're trying to do:&lt;/P&gt;
&lt;PRE&gt;data have;
  fullpath='/workspace/alphabuilder/data-jp/D160125.DB';
  call scan(fullpath, -1, position, length,'/');
  folder=substr(fullpath,1,position-1);
  filename=scan(fullpath,-1,'/');
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2017 23:50:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Populating-data-set-from-Filename-dirlist-pipe-quot-find/m-p/369369#M88173</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-06-21T23:50:08Z</dc:date>
    </item>
    <item>
      <title>Re: Populating data set from Filename dirlist pipe "find tmpFolder"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Populating-data-set-from-Filename-dirlist-pipe-quot-find/m-p/369370#M88174</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; FOLDER=substr(_infile_,29,find(_infile_,'/',-999)-29);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Jun 2017 00:02:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Populating-data-set-from-Filename-dirlist-pipe-quot-find/m-p/369370#M88174</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-06-22T00:02:17Z</dc:date>
    </item>
    <item>
      <title>Re: Populating data set from Filename dirlist pipe "find tmpFolder"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Populating-data-set-from-Filename-dirlist-pipe-quot-find/m-p/369382#M88182</link>
      <description>&lt;P&gt;There's also the FINFO approach.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/kb/40/934.html" target="_blank"&gt;http://support.sas.com/kb/40/934.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/** Macro technique **/                                                                                                                 
%macro FileAttribs(filename);                                                                                                           
   %local rc fid fidc;                                                                                                                   
   %local Bytes CreateDT ModifyDT;                                                                                                       
   %let rc=%sysfunc(filename(onefile,&amp;amp;filename));                                                                                       
   %let fid=%sysfunc(fopen(&amp;amp;onefile));                                                                                                  
   %let Bytes=%sysfunc(finfo(&amp;amp;fid,File Size (bytes)));                                                                                  
   %let CreateDT=%qsysfunc(finfo(&amp;amp;fid,Create Time));                                                                                     
   %let ModifyDT=%qsysfunc(finfo(&amp;amp;fid,Last Modified));                                                                                   
   %let fidc=%sysfunc(fclose(&amp;amp;fid));                                                                                                    
   %let rc=%sysfunc(filename(onefile));                                                                                                 
   %put NOTE: File size of &amp;amp;filename is &amp;amp;Bytes bytes;                                                                                  
   %put NOTE- Created &amp;amp;CreateDT;                                                                                                       
   %put NOTE- Last modified &amp;amp;ModifyDT;                                                                                                 
%mend FileAttribs;                                                                                                                      
                                                                                                                                        
/** Just pass in the path and file name **/                                                                                             
%FileAttribs(c:\aaa.txt)                                                                                                                
                                                                                                                                        
                                                                                                                                        
/** Non-macro technique **/                                                                                                             
filename fileref 'c:\aaa.txt';                                                                                                          
data a(drop=fid);                                                                                                                       
   infile fileref truncover obs=1;                                                                                                       
   fid=fopen('fileref');                                                                                                                 
   Bytes=finfo(fid,'File Size (bytes)');                                                                                                 
   crdate=finfo(fid,'Create Time');                                                                                                      
   moddate=finfo(fid,'Last Modified');                                                                                                   
run;                                                                                                                                    
                                                                                                                                        
proc print;                                                                                                                             
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Jun 2017 03:13:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Populating-data-set-from-Filename-dirlist-pipe-quot-find/m-p/369382#M88182</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-22T03:13:17Z</dc:date>
    </item>
    <item>
      <title>Re: Populating data set from Filename dirlist pipe "find tmpFolder"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Populating-data-set-from-Filename-dirlist-pipe-quot-find/m-p/369409#M88190</link>
      <description>&lt;P&gt;I think you're overcomplicating things:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input date :mmddyy8. time :time20. pathstr :$100.;
format
  date mmddyy8.
  time time11.2
  file_name $50.
;
file_name = scan(pathstr,-1,'/');
drop pathstr;
cards;
06/16/17 09:40:19.8344320410 /workspace/alphabuilder/data-jp/D160125.DB
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It presumes that nobody fucked up by putting blanks into filenames; if that is a possibility, the initial read for pathstr would have to be done with a fixed format from a given position.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 08:18:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Populating-data-set-from-Filename-dirlist-pipe-quot-find/m-p/369409#M88190</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-06-22T08:18:28Z</dc:date>
    </item>
  </channel>
</rss>

