<?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 Getting Filenames in Directory as a Variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Getting-Filenames-in-Directory-as-a-Variable/m-p/742592#M232325</link>
    <description>&lt;P&gt;Hello!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For reporting purposes, I am trying to get a list of files from a directory as a variable in a sas dataset. I am using the following code to access a test directory (unfortunately I can't show the actual filenames in the actual directory, so below has a lot of dummy code/placeholders):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename pipedir pipe "dir test/users/documents" lrecl=5000;  

data test;
	infile pipedir truncover; 
    input line $char1000.;
    put line;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, instead of one filename per obs, the variable line in work.test has 4 filenames per obs:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="yawenyu929_0-1621492741131.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59594i4270EA2FF3DD058F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="yawenyu929_0-1621492741131.png" alt="yawenyu929_0-1621492741131.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Here's how work.test should look:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="yawenyu929_1-1621492772240.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59595i7C739AA80D6CD3CF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="yawenyu929_1-1621492772240.png" alt="yawenyu929_1-1621492772240.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried 'dlm=".doc"' and 'dlm=" "', but I was not able to fix it. Does anyone have any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Yawen&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 20 May 2021 06:54:58 GMT</pubDate>
    <dc:creator>yawenyu929</dc:creator>
    <dc:date>2021-05-20T06:54:58Z</dc:date>
    <item>
      <title>Getting Filenames in Directory as a Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Filenames-in-Directory-as-a-Variable/m-p/742592#M232325</link>
      <description>&lt;P&gt;Hello!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For reporting purposes, I am trying to get a list of files from a directory as a variable in a sas dataset. I am using the following code to access a test directory (unfortunately I can't show the actual filenames in the actual directory, so below has a lot of dummy code/placeholders):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename pipedir pipe "dir test/users/documents" lrecl=5000;  

data test;
	infile pipedir truncover; 
    input line $char1000.;
    put line;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, instead of one filename per obs, the variable line in work.test has 4 filenames per obs:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="yawenyu929_0-1621492741131.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59594i4270EA2FF3DD058F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="yawenyu929_0-1621492741131.png" alt="yawenyu929_0-1621492741131.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Here's how work.test should look:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="yawenyu929_1-1621492772240.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59595i7C739AA80D6CD3CF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="yawenyu929_1-1621492772240.png" alt="yawenyu929_1-1621492772240.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried 'dlm=".doc"' and 'dlm=" "', but I was not able to fix it. Does anyone have any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Yawen&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 May 2021 06:54:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Filenames-in-Directory-as-a-Variable/m-p/742592#M232325</guid>
      <dc:creator>yawenyu929</dc:creator>
      <dc:date>2021-05-20T06:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Filenames in Directory as a Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Filenames-in-Directory-as-a-Variable/m-p/742630#M232345</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;add the /b parameter and enclose your path in double quotes like in&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename pipedir pipe "dir ""C:\temp\*.*"" /b" lrecl=5000;  &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 May 2021 10:58:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Filenames-in-Directory-as-a-Variable/m-p/742630#M232345</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2021-05-20T10:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Filenames in Directory as a Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Filenames-in-Directory-as-a-Variable/m-p/742631#M232346</link>
      <description>&lt;P&gt;Use SAS on-board tools:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data filenames;
length
  fref $8
  fname $200
;
rc = filename(fref,"test/users/documents");
did = dopen(fref);
if did ne 0
then do;
  do i = 1 to dnum(did);
    fname = dread(did,i);
    output;
  end;
  rc = dclose(did);
end;
rc = filename(fref,"");
keep fname;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 May 2021 11:09:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Filenames-in-Directory-as-a-Variable/m-p/742631#M232346</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-05-20T11:09:04Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Filenames in Directory as a Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Filenames-in-Directory-as-a-Variable/m-p/742637#M232349</link>
      <description>&lt;P&gt;What operating system is your SAS code running on?&amp;nbsp; Check the macro variables SYSSCP and SYSSCPL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your output looks like the output of ls on unix to a terminal.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if you are using Unix why did you use dir instead of ls as the command?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also when piped to another process ls will automatically generate only one name per line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try using ls instead of dir as the command.&lt;/P&gt;</description>
      <pubDate>Thu, 20 May 2021 12:18:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Filenames-in-Directory-as-a-Variable/m-p/742637#M232349</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-20T12:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Filenames in Directory as a Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Filenames-in-Directory-as-a-Variable/m-p/742693#M232364</link>
      <description>&lt;P&gt;It's amazing that you realized I was programming in a unix environment. Thank you so much!&lt;/P&gt;</description>
      <pubDate>Thu, 20 May 2021 15:58:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Filenames-in-Directory-as-a-Variable/m-p/742693#M232364</guid>
      <dc:creator>yawenyu929</dc:creator>
      <dc:date>2021-05-20T15:58:28Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Filenames in Directory as a Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Filenames-in-Directory-as-a-Variable/m-p/742698#M232367</link>
      <description>&lt;P&gt;I guess they set up an alias for the ls command called dir, for the people coming over from Windows.&lt;/P&gt;</description>
      <pubDate>Thu, 20 May 2021 16:16:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Filenames-in-Directory-as-a-Variable/m-p/742698#M232367</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-05-20T16:16:43Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Filenames in Directory as a Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Filenames-in-Directory-as-a-Variable/m-p/742711#M232375</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I guess they set up an alias for the ls command called dir, for the people coming over from Windows.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It must be something other than an alias.&amp;nbsp; The ls command knows when it is being piped and adjusts how it displays multiple names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On my Red Hat Linux server someone has installed a dir command that appears to be from the GNU library.&amp;nbsp; It seems to behave like the symptom in this question.&lt;/P&gt;</description>
      <pubDate>Thu, 20 May 2021 17:04:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Filenames-in-Directory-as-a-Variable/m-p/742711#M232375</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-20T17:04:08Z</dc:date>
    </item>
  </channel>
</rss>

