<?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: All SAS program names in one line in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845841#M334389</link>
    <description>&lt;P&gt;Thank you so much, this works.&lt;/P&gt;</description>
    <pubDate>Wed, 23 Nov 2022 04:59:26 GMT</pubDate>
    <dc:creator>Leo9</dc:creator>
    <dc:date>2022-11-23T04:59:26Z</dc:date>
    <item>
      <title>All SAS program names in one line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845576#M334294</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to put all SAS program names in one file and in one line. I already have list of program names in a file. I need to create a simple txt file and put program names like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;abc.sas xyz.sas abc2.sas etc.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can you achieve this with put and infile statement ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2022 22:50:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845576#M334294</guid>
      <dc:creator>Leo9</dc:creator>
      <dc:date>2022-11-21T22:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: All SAS program names in one line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845579#M334295</link>
      <description>&lt;P&gt;How is the file you already have structured? Can you show an example?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/I-need-to-export-data-from-SAS-to-DAT-file-with-only-1-line/m-p/843618" target="_self"&gt;This question&lt;/A&gt; shows how to create a text file from a SAS data set as a single line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Change the file extension to txt&lt;/LI&gt;
&lt;LI&gt;Change the delimiter to space&lt;/LI&gt;
&lt;LI&gt;Remove DSD option (not needed)&lt;/LI&gt;
&lt;LI&gt;Remove END option (not used)&lt;/LI&gt;
&lt;LI&gt;Assumes Have is the list of program names&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
file "test.txt" recfm=N dlm=' ' lrecl=500000;
set have;
put (_all_)(:) +(-1) @;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/91198"&gt;@Leo9&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to put all SAS program names in one file and in one line. I already have list of program names in a file. I need to create a simple txt file and put program names like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;abc.sas xyz.sas abc2.sas etc.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can you achieve this with put and infile statement ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2022 23:45:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845579#M334295</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-11-21T23:45:54Z</dc:date>
    </item>
    <item>
      <title>Re: All SAS program names in one line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845585#M334299</link>
      <description>&lt;P&gt;Thank you. In your example there has to be a text file already created to put the program names. I want to create a txt file within the program itself (without manually creating it) and then use that text file to put the program names.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 01:03:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845585#M334299</guid>
      <dc:creator>Leo9</dc:creator>
      <dc:date>2022-11-22T01:03:00Z</dc:date>
    </item>
    <item>
      <title>Re: All SAS program names in one line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845586#M334300</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/91198"&gt;@Leo9&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you. In your example there has to be a text file already created to put the program names. I want to create a txt file within the program itself (without manually creating it) and then use that text file to put the program names.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your description is backwards.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You cannot use a text file to put names.&amp;nbsp; You use SAS code to put the names into the text file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The program shown was creating a text file.&amp;nbsp; It assumed you had the list of filenames in a dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So let's assume you have dataset named PROGRAMS which has a variable named FILENAME and you want to create a file named 'program_names.txt'.&amp;nbsp; Then this program will write one line to the file with a space between each filename.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  file 'program_names.txt';
  set programs;
  put filename @ ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the filenames might have spaces in them then perhaps you want to add the DSD and DLM option to the file statement.&amp;nbsp; That way SAS will quote the names of any files that have spaces in them.&amp;nbsp; Otherwise the list would be confusing.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  file 'program_names.txt' dsd dlm=' ';
  set programs;
  put filename @ ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 01:23:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845586#M334300</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-22T01:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: All SAS program names in one line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845625#M334322</link>
      <description>&lt;P&gt;From where do you get the program names? A dataset, another text file, a directory, or a whole directory tree? Or several directory trees?&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 08:19:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845625#M334322</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-11-22T08:19:17Z</dc:date>
    </item>
    <item>
      <title>Re: All SAS program names in one line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845705#M334339</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/91198"&gt;@Leo9&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you. In your example there has to be a text file already created to put the program names. I want to create a txt file within the program itself (without manually creating it) and then use that text file to put the program names.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No, there needs to be a SAS data set with the program names.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where are the program names? Do you need to look through a folder and file all files? Or something else.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please explain what this means from your original post:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;I already have list of program names in a file&lt;/STRONG&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 22 Nov 2022 16:24:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845705#M334339</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-11-22T16:24:59Z</dc:date>
    </item>
    <item>
      <title>Re: All SAS program names in one line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845769#M334360</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your responses. I should have been more clearer in my original post.&amp;nbsp; Basically, I am reading names of all the sas programs from a given directory and then I am trying to put them in a text file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- First read all program names&amp;nbsp;&lt;/P&gt;&lt;P&gt;- Put all these program names in a text file&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Here is the full code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;filename mybatch "/space/kstr395/brim/misc/programs/batch.txt";&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro list_files(dir,ext);&lt;BR /&gt;%local filrf rc did memcnt name i;&lt;BR /&gt;%let rc=%sysfunc(filename(filrf,&amp;amp;dir));&lt;BR /&gt;%let did=%sysfunc(dopen(&amp;amp;filrf));&lt;/P&gt;&lt;P&gt;%if &amp;amp;did eq 0 %then %do;&lt;BR /&gt;%put Directory &amp;amp;dir cannot be open or does not exist;&lt;BR /&gt;%return;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;data _null_ ;&lt;BR /&gt;file&amp;nbsp; "/space/kstr395/brim/misc/programs/batch.txt" recfm=N dlm=' ' lrecl=500000;&lt;/P&gt;&lt;P&gt;%do i = 1 %to %sysfunc(dnum(&amp;amp;did));&lt;BR /&gt;%let name=%qsysfunc(dread(&amp;amp;did,&amp;amp;i));&lt;BR /&gt;%if %qupcase(%qscan(&amp;amp;name,-1,.)) = %upcase(&amp;amp;ext) %then %do;&lt;BR /&gt;%put &amp;amp;dir/&amp;amp;name @@;&lt;/P&gt;&lt;P&gt;put &amp;amp;name&amp;nbsp;@@ ;&lt;BR /&gt;%end;&lt;BR /&gt;%else %if %qscan(&amp;amp;name,2,.) = %then %do;&lt;BR /&gt;%list_files(&amp;amp;dir/&amp;amp;name,&amp;amp;ext)&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%let rc=%sysfunc(dclose(&amp;amp;did));&lt;BR /&gt;%let rc=%sysfunc(filename(filrf));&lt;/P&gt;&lt;P&gt;%mend list_files;&lt;BR /&gt;%list_files( %str(/space/kstr395/brim/misc/programs),sas) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am getting an error "Data Step Component Object Failure. Aborted during compilation phase"&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 20:44:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845769#M334360</guid>
      <dc:creator>Leo9</dc:creator>
      <dc:date>2022-11-22T20:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: All SAS program names in one line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845770#M334361</link>
      <description>&lt;P&gt;Why do you have all of that macro code in there?&amp;nbsp; You are already running a data step so just call the functions directly.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro list_files(dir,ext,file);
data _null_;
  length filrf $8 ;
  rc=filename(filrf,"&amp;amp;dir");
  did=dopen(filrf);
  if did=0 then do;
     putlog "ERROR: Directory &amp;amp;dir cannot be open or does not exist";
     stop;
  end;
  file &amp;amp;file recfm=N ;
  do i=1 to dnum(did);
    length name $256;
    name=dread(did,i);
    if index(name,'.') and lowcase(scan(name,-1,'.'))=lowcase("&amp;amp;ext") then do;
      put name ;
    end;
  end;
  rc = dclose(did);
  rc = filename(filrf);
run;
%mend list_files;

filename mybatch "/space/kstr395/brim/misc/programs/batch.txt";
%list_files(dir=/space/kstr395/brim/misc/programs,ext=sas,file=mybatch)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 21:00:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845770#M334361</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-22T21:00:19Z</dc:date>
    </item>
    <item>
      <title>Re: All SAS program names in one line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845772#M334362</link>
      <description>&lt;P&gt;If you remove all the DATA step code, does the macro work?&amp;nbsp; i.e. as a recursive directory crawler that %PUTs to the log a list of the .sas files found, does that work?&amp;nbsp; I would start by getting that to work, before trying to adapt it to save results in a file.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 21:03:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845772#M334362</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-11-22T21:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: All SAS program names in one line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845775#M334363</link>
      <description>&lt;P&gt;If you want to traverse a whole subdirectory tree then use something like this.&lt;/P&gt;
&lt;P&gt;&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;But then you have to decide how you want to write the names into the file.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want to ignore the directory name?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;program1.sas program2.sas program1.sas program2.sas&lt;/PRE&gt;
&lt;P&gt;Do you want to write the subdirectory name also?&lt;/P&gt;
&lt;PRE&gt;program1.sas program2.sas subdir/program1.sas subdir/program2.sas&lt;/PRE&gt;
&lt;P&gt;Does that include the top level directory name also?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;/top/program1.sas /top/program2.sas /top/subdir/program1.sas /top/subdir/program2.sas&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Nov 2022 21:17:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845775#M334363</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-22T21:17:58Z</dc:date>
    </item>
    <item>
      <title>Re: All SAS program names in one line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845785#M334367</link>
      <description>&lt;P&gt;Thank you for your response. I just want program name like&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;program1.sas program2.sas program1.sas program2.sas&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Nov 2022 22:02:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845785#M334367</guid>
      <dc:creator>Leo9</dc:creator>
      <dc:date>2022-11-22T22:02:32Z</dc:date>
    </item>
    <item>
      <title>Re: All SAS program names in one line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845786#M334368</link>
      <description>&lt;P&gt;Then try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%dirtree(/space/kstr395/brim/misc/programs)
data _null_;
  set dirtree;
  if index(filename,'.') and lowcase(scan(filename,-1,'.'))='sas';
  file "/space/kstr395/brim/misc/programs/batch.txt" recfm=n ;
  put filename;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Nov 2022 22:15:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845786#M334368</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-22T22:15:27Z</dc:date>
    </item>
    <item>
      <title>Re: All SAS program names in one line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845841#M334389</link>
      <description>&lt;P&gt;Thank you so much, this works.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2022 04:59:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845841#M334389</guid>
      <dc:creator>Leo9</dc:creator>
      <dc:date>2022-11-23T04:59:26Z</dc:date>
    </item>
    <item>
      <title>Re: All SAS program names in one line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845842#M334390</link>
      <description>&lt;P&gt;Thank you! This solution works too. The macro is really great.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2022 05:00:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/All-SAS-program-names-in-one-line/m-p/845842#M334390</guid>
      <dc:creator>Leo9</dc:creator>
      <dc:date>2022-11-23T05:00:03Z</dc:date>
    </item>
  </channel>
</rss>

