<?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: How to write (all) my sas code file(s) to a txt file? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-all-my-sas-code-file-s-to-a-txt-file/m-p/843339#M333417</link>
    <description>&lt;P&gt;You could make:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if scan(lowcase(fname),-1,".") = 'sas' then output;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in the first datastep to make filtering faster.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Wed, 09 Nov 2022 12:08:53 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2022-11-09T12:08:53Z</dc:date>
    <item>
      <title>How to write (all) my sas code file(s) to a txt file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-all-my-sas-code-file-s-to-a-txt-file/m-p/843307#M333404</link>
      <description>&lt;P&gt;In SAS Viya 3.5 SAS Studio I make use of projects to save my SAS codes in an organized way. Furthermore I create code snippets for partial tasks I use frequently.&lt;/P&gt;
&lt;P&gt;Nevertheless sometimes I have a 'dejà vue' when facing a new challenge. It goes like "Arne, you solved this once using a specific cas action 'transpose'."&lt;/P&gt;
&lt;P&gt;Now I would like to (regex) search for 'transpose' in all my sas codes.&lt;/P&gt;
&lt;P&gt;But the built-in seach-in function is very rudimentary.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So my idea is to write all the sas code to a txt file.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My starting points:&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;the proc printto but I only know to use it for the log files.&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Or the data _null_ with put and file statement but I only know how to execute a sas file with the %include statement, but not to read or print a sas code file&amp;nbsp;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2022 10:06:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-all-my-sas-code-file-s-to-a-txt-file/m-p/843307#M333404</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2022-11-09T10:06:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to write (all) my sas code file(s) to a txt file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-all-my-sas-code-file-s-to-a-txt-file/m-p/843311#M333406</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/127222"&gt;@acordes&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are your files with code stored in one place e.g., a folder like: /Deskto/myCodes/*.sas ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2022 10:20:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-all-my-sas-code-file-s-to-a-txt-file/m-p/843311#M333406</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-11-09T10:20:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to write (all) my sas code file(s) to a txt file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-all-my-sas-code-file-s-to-a-txt-file/m-p/843313#M333407</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;yes.&lt;/P&gt;
&lt;P&gt;For example I would like to export / append all sas codes in the specified project folder to a txt file.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code of the image has nothing to do with my question.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It serves only to share with you my folder path and how I use it for other tasks.&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="pic1.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77106i5C0C1260264A787A/image-size/large?v=v2&amp;amp;px=999" role="button" title="pic1.png" alt="pic1.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2022 10:30:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-all-my-sas-code-file-s-to-a-txt-file/m-p/843313#M333407</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2022-11-09T10:30:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to write (all) my sas code file(s) to a txt file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-all-my-sas-code-file-s-to-a-txt-file/m-p/843317#M333411</link>
      <description>&lt;P&gt;lets assume the following setup:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*lets assume the following setup*/

filename f "R:\folder with my sas codes\";

data _null_;
  file f(code1.sas);
  put "data test;" / "x = 17; output;" / "x = 42; output;" / "run;";

  file f(code2.sas);
  put "proc sort data = test;" / "by x;" / "run;";

  file f(code3.sas);
  put "proc transpose data = test out = transposed_data;" / "var x;" / "run;";
run;

/* test if they work */
%include f(code1.sas);
%include f(code2.sas);
%include f(code3.sas);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* searching */

filename search "R:\folder with my sas codes\*";


%let myStr = proc; /* string you are looking */

data result;
length file $ 256 code_line $ 2048;
infile search filename = file end=end;
input;
lineNumber+1;
filename = file;
code_line= _infile_;
if find(_infile_, "&amp;amp;myStr.", "i") then output;
if end then lineNumber=0;
run;

proc print data=result;;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;a solution you are looking for?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2022 10:40:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-all-my-sas-code-file-s-to-a-txt-file/m-p/843317#M333411</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-11-09T10:40:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to write (all) my sas code file(s) to a txt file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-all-my-sas-code-file-s-to-a-txt-file/m-p/843326#M333413</link>
      <description>&lt;P&gt;Thanks Bart.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Only for completeness, I had to wrap your solution into a data null &amp;amp; call execute after writing the files in the folder to a file.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/td-p/674065" target="_self"&gt;https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/td-p/674065&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Credits to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think it's sas viya specific how it can access path locations.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it works and does exactly what I was looking for.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename myfldr filesrvc folderPath='/Projects/Portugal/';

data filenames;
length  fname $200;
did = dopen('myfldr');
do i = 1 to dnum(did);
  fname = dread(did,i);
  output;
end;
did = dclose(did);
keep fname;
run;

%let myStr = symputx; /* string you are looking */

data _null_;
set filenames;
if index(lowcase(fname), '.sas') then 
call execute ('
filename search FILESRVC FOLDERPATH="/Projects/Portugal/" FILENAME=' || quote(strip(fname)) || ' ;

data temp;
length file $ 256 code_line $ 2048;
infile search filename = file end=end;
input;
lineNumber+1;
filename = file;
code_line= _infile_;
if find(_infile_, "&amp;amp;myStr.", "i") then output;
if end then lineNumber=0;
run;

proc append base=result data=temp;
run;
');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2022 11:35:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-all-my-sas-code-file-s-to-a-txt-file/m-p/843326#M333413</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2022-11-09T11:35:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to write (all) my sas code file(s) to a txt file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-all-my-sas-code-file-s-to-a-txt-file/m-p/843339#M333417</link>
      <description>&lt;P&gt;You could make:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if scan(lowcase(fname),-1,".") = 'sas' then output;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in the first datastep to make filtering faster.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2022 12:08:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-all-my-sas-code-file-s-to-a-txt-file/m-p/843339#M333417</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-11-09T12:08:53Z</dc:date>
    </item>
  </channel>
</rss>

