<?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: listing directories using ls in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/listing-directories-using-ls/m-p/475762#M286022</link>
    <description>&lt;P&gt;I wouldn't use the X command, but if you do then add quotes around the command you want to run so that the command does not get interpreted by SAS or the SAS macro processor.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename list temp;

x "ls -d ~/*/ &amp;gt; '%sysfunc(pathname(list))'" ;
data _null_;
  infile list ;
  input;
  put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or easier still just use the PIPE engine and skip the temporary file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile "ls -d ~/*/" pipe ;
  input ;
  put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 05 Jul 2018 18:16:03 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-07-05T18:16:03Z</dc:date>
    <item>
      <title>listing directories using ls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/listing-directories-using-ls/m-p/475720#M286019</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So this is similar but different from previous posts.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a list of directories (not files) in a DIS project.&lt;/P&gt;&lt;P&gt;In DIS I can get a list of all the folder contents using&amp;nbsp;x ls -lp &amp;amp;file_path. &amp;gt;/tmp/folderlisting.csv;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In Bash script&amp;nbsp;ls -d */ "filepath" works perfectly. However the */ is not working in SAS as it treats this as a comment end. Quoting this has not helped.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, any help I could get in finding a solution or alternative to x&amp;nbsp;&lt;SPAN&gt;ls -d */ "&amp;amp;filepath." &amp;gt;/tmp/folderlisting.csv; would be appreciated.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am aware that could use multiple lines of code to search through the full output and create a new file but i am looking for an efficient streamlined solution.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;NB I have also tried | grep ^d but again DIS doesn't&amp;nbsp;like this.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 16:14:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/listing-directories-using-ls/m-p/475720#M286019</guid>
      <dc:creator>JordanWood</dc:creator>
      <dc:date>2018-07-05T16:14:42Z</dc:date>
    </item>
    <item>
      <title>Re: listing directories using ls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/listing-directories-using-ls/m-p/475724#M286020</link>
      <description>Try SYSEXEC or CALL SYSTEM instead of an X command. You can enclose your command in quotes which will help it process correctly.</description>
      <pubDate>Thu, 05 Jul 2018 16:20:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/listing-directories-using-ls/m-p/475724#M286020</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-05T16:20:49Z</dc:date>
    </item>
    <item>
      <title>Re: listing directories using ls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/listing-directories-using-ls/m-p/475756#M286021</link>
      <description>&lt;P&gt;Use the filename pipe method:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename oscmd pipe "ls -d */ '&amp;amp;filepath.' 2&amp;gt;&amp;amp;1";

data _null_;
infile oscmd;
input;
put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then look at the log and see how you can use the output of the ls.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 18:03:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/listing-directories-using-ls/m-p/475756#M286021</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-05T18:03:03Z</dc:date>
    </item>
    <item>
      <title>Re: listing directories using ls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/listing-directories-using-ls/m-p/475762#M286022</link>
      <description>&lt;P&gt;I wouldn't use the X command, but if you do then add quotes around the command you want to run so that the command does not get interpreted by SAS or the SAS macro processor.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename list temp;

x "ls -d ~/*/ &amp;gt; '%sysfunc(pathname(list))'" ;
data _null_;
  infile list ;
  input;
  put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or easier still just use the PIPE engine and skip the temporary file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile "ls -d ~/*/" pipe ;
  input ;
  put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 18:16:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/listing-directories-using-ls/m-p/475762#M286022</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-05T18:16:03Z</dc:date>
    </item>
    <item>
      <title>Re: listing directories using ls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/listing-directories-using-ls/m-p/476839#M286023</link>
      <description>&lt;P&gt;Thanks for the help. I tried lots of the variants suggested but the one that worked is ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%sysexec (ls -l "&amp;amp;file_path" | grep ^d&amp;nbsp; &amp;gt; /tmp/folderlisting.csv);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;also had to do some double quoting of the variable file_path when setting it but that is all part of the differences in EG and DIS.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 15:00:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/listing-directories-using-ls/m-p/476839#M286023</guid>
      <dc:creator>JordanWood</dc:creator>
      <dc:date>2018-07-10T15:00:44Z</dc:date>
    </item>
  </channel>
</rss>

