<?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 a Directory Correctly in a Filename Statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-Directory-Correctly-in-a-Filename-Statement/m-p/314970#M68654</link>
    <description>&lt;P&gt;Your filename statement may cause an issue:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;&lt;SPAN&gt;FILENAME dirlist PIPE 'dir /B "&amp;amp;wheredeyat\*.log"'; /* dir /B */&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;macro variable will not be resolves inside single quotes ('..&amp;amp;xxxx ....').&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;try use only double-quotes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;FILENAME dirlist PIPE "dir /B ""&amp;amp;wheredeyat\*.log"" "; &amp;nbsp; /* dir /B */&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 28 Nov 2016 21:24:52 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2016-11-28T21:24:52Z</dc:date>
    <item>
      <title>Reading a Directory Correctly in a Filename Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-Directory-Correctly-in-a-Filename-Statement/m-p/314925#M68646</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am having a difficult time getting SAS to read a directory correctly. I am creating a process that notifies me of any errors in my log files from nightly processes. At this point I am merely trying to get the list of all log files located in the specific folder, but SAS does not seem to read my path correctly. Here is my code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*Logs location;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%LET&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; wheredeyat=\\vs-app-SAS01\Scheduled Tasks\Task Logs;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*List all the files in the current directory;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;FILENAME&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; dirlist &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;PIPE&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="3"&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'dir /B "&amp;amp;wheredeyat\*.log"'&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/* dir /B */&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; dirlist;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;LENGTH&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; fname $&lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;256&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;INFILE&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; dirlist &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;LENGTH&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;=reclen &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;TRUNCOVER&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;INPUT&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; fname &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$varying256.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; reclen;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;&lt;FONT size="3"&gt;Here is the log to the above code:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR&lt;/P&gt;
&lt;P&gt;21&lt;/P&gt;
&lt;P&gt;22 GOPTIONS ACCESSIBLE;&lt;/P&gt;
&lt;P&gt;23 OPTIONS MSGLEVEL=I MPRINT=ON SORTSIZE=512m;&lt;/P&gt;
&lt;P&gt;24&lt;/P&gt;
&lt;P&gt;25&lt;/P&gt;
&lt;P&gt;26 *Logs location;&lt;/P&gt;
&lt;P&gt;27 %LET wheredeyat=\\vs-app-SAS01\Scheduled Tasks\Task Logs;&lt;/P&gt;
&lt;P&gt;28&lt;/P&gt;
&lt;P&gt;29 *List all the files in the current directory;&lt;/P&gt;
&lt;P&gt;30 FILENAME dirlist PIPE 'dir /B "&amp;amp;wheredeyat\*.log"'; /* dir /B */&lt;/P&gt;
&lt;P&gt;31 DATA dirlist;&lt;/P&gt;
&lt;P&gt;32 LENGTH fname $256;&lt;/P&gt;
&lt;P&gt;33 INFILE dirlist LENGTH=reclen TRUNCOVER;&lt;/P&gt;
&lt;P&gt;34 INPUT fname $varying256. reclen;&lt;/P&gt;
&lt;P&gt;35 RUN;&lt;/P&gt;
&lt;P&gt;NOTE: The infile DIRLIST is:&lt;/P&gt;
&lt;P&gt;Unnamed Pipe Access Device,&lt;/P&gt;
&lt;P&gt;PROCESS=dir /B "&amp;amp;wheredeyat\*.log",RECFM=V,&lt;/P&gt;
&lt;P&gt;LRECL=32767&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;Stderr output:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;The system cannot find the file specified.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;NOTE: 0 records were read from the infile DIRLIST.&lt;/P&gt;
&lt;P&gt;NOTE: The data set WORK.DIRLIST has 0 observations and 1 variables.&lt;/P&gt;
&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;/P&gt;
&lt;P&gt;real time 0.04 seconds&lt;/P&gt;
&lt;P&gt;cpu time 0.01 seconds&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Nov 2016 19:08:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-Directory-Correctly-in-a-Filename-Statement/m-p/314925#M68646</guid>
      <dc:creator>NathanOch</dc:creator>
      <dc:date>2016-11-28T19:08:28Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a Directory Correctly in a Filename Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-Directory-Correctly-in-a-Filename-Statement/m-p/314937#M68649</link>
      <description>Is it possible that SAS is reading forward slash in your macro variable &amp;amp;wheredeyat\ as part of the macro?  Have you tried using "&amp;amp;wheredeyat.\ with the period as macro string terminator?</description>
      <pubDate>Mon, 28 Nov 2016 20:09:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-Directory-Correctly-in-a-Filename-Statement/m-p/314937#M68649</guid>
      <dc:creator>Haris</dc:creator>
      <dc:date>2016-11-28T20:09:08Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a Directory Correctly in a Filename Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-Directory-Correctly-in-a-Filename-Statement/m-p/314970#M68654</link>
      <description>&lt;P&gt;Your filename statement may cause an issue:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;&lt;SPAN&gt;FILENAME dirlist PIPE 'dir /B "&amp;amp;wheredeyat\*.log"'; /* dir /B */&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;macro variable will not be resolves inside single quotes ('..&amp;amp;xxxx ....').&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;try use only double-quotes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;FILENAME dirlist PIPE "dir /B ""&amp;amp;wheredeyat\*.log"" "; &amp;nbsp; /* dir /B */&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Nov 2016 21:24:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-Directory-Correctly-in-a-Filename-Statement/m-p/314970#M68654</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-11-28T21:24:52Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a Directory Correctly in a Filename Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-Directory-Correctly-in-a-Filename-Statement/m-p/314972#M68655</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Reading a Directory Correctly in a Filename Statement

If you double the double quotes instead of using single quotes it should work. At least it worked on my power workstation.

see working code

HAVE THIS TREE STRUCTURE
========================

Folder PATH listing for volume backup
Volume serial number is 5EA1-ABB0

D:\TXT
\---wheredeyat
foo1st.log
foo1st.txt
foo2nd.log
foo2nd.txt

WANT
====

FNAME=foo1st.log
FNAME=foo2nd.log

WORKING CODE ( note the dubling of quotes)
==========================================

FILENAME dirlist PIPE "dir /B ""&amp;amp;wheredeyat\*.log""";

FULL SOLUTION
=============

* create a directory and some file;
data _null_;
    newdir=dcreate('wheredeyat',"d:/txt/");
    rc=dosubl(resolve('
       data _null_;
         file "d:/txt/wheredeyat/foo1st.log";
         put "foo1st";
         file "d:/txt/wheredeyat/foo2nd.log";
         put "foo2nd";
       '));
    stop;
run;quit;

* layout the tree;
filename pipetree pipe "tree ""d:/txt"" /F /A" lrecl=5000;
data _null_;
infile pipetree truncover;
input dirlist $char1000.;
*if index(dirlist,'.') =0;
put dirlist;
run;

SOLUTION WITH MINOR MODIFICATION OF YOUR CODE

%LET wheredeyat=d:\txt\wheredeyat;

*List all the files in the current directory;
FILENAME dirlist PIPE "dir /B ""&amp;amp;wheredeyat\*.log""";
DATA dirlist;
LENGTH fname $256;
INFILE dirlist LENGTH=reclen TRUNCOVER;
INPUT fname $varying256. reclen;
put fname=;
RUN;

FNAME=foo1st.log
FNAME=foo2nd.log

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Nov 2016 21:26:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-Directory-Correctly-in-a-Filename-Statement/m-p/314972#M68655</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2016-11-28T21:26:24Z</dc:date>
    </item>
  </channel>
</rss>

