<?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: X COmmand To Modify File? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/X-COmmand-To-Modify-File/m-p/650868#M195204</link>
    <description>&lt;P&gt;Your data step code is much too complicated. Use mine as a blueprint.&lt;/P&gt;
&lt;P&gt;In particular, this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if lag("&amp;amp;&amp;amp;filenm&amp;amp;i") ne "&amp;amp;&amp;amp;filenm&amp;amp;i" then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;makes no sense, as lag cannot work with strings, only data step variables. It seems you tried to adapt code that reads filenames from a dataset and reads multiple files, but you only need to read and write a single file in one step.&lt;/P&gt;</description>
    <pubDate>Tue, 26 May 2020 18:03:53 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-05-26T18:03:53Z</dc:date>
    <item>
      <title>X COmmand To Modify File?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/X-COmmand-To-Modify-File/m-p/650350#M195016</link>
      <description>&lt;P&gt;Hi - does anyone know how to use the "X" command to modify a file? I would like to insert a line at the beginning and end of file. This would be in Unix/linux. Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 25 May 2020 05:55:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/X-COmmand-To-Modify-File/m-p/650350#M195016</guid>
      <dc:creator>shl007</dc:creator>
      <dc:date>2020-05-25T05:55:14Z</dc:date>
    </item>
    <item>
      <title>Re: X COmmand To Modify File?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/X-COmmand-To-Modify-File/m-p/650374#M195018</link>
      <description>&lt;P&gt;See here:&amp;nbsp;&lt;A href="https://unix.stackexchange.com/questions/20573/sed-insert-text-after-the-last-line" target="_blank" rel="noopener"&gt;https://unix.stackexchange.com/questions/20573/sed-insert-text-after-the-last-line&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It also includes the sed comnand for inserting at the top.&lt;/P&gt;
&lt;P&gt;You can do the same thing with pure SAS means:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date _null_;
infile "file_to_read";
file "newfile" end=done;
input;
if _n_ = 1 then put "text for top";
put _infile;
if done then put "text for bottom";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and then use the SAS file functions in a follow-up step to remove the old file and rename the new.&lt;/P&gt;</description>
      <pubDate>Mon, 25 May 2020 07:32:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/X-COmmand-To-Modify-File/m-p/650374#M195018</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-25T07:32:22Z</dc:date>
    </item>
    <item>
      <title>Re: X COmmand To Modify File?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/X-COmmand-To-Modify-File/m-p/650775#M195173</link>
      <description>&lt;P&gt;Yeah I tried the SAS datastep approach, but for some reason it is truncating my input line even though I'm specifying LRECL = 32767. So I'm going with the Unix command and running that through the "x" command in SAS. As such, the following x command syntax works for me in SAS to insert at the END of the file:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;x 'echo "text you want to insert" &amp;gt;&amp;gt; filepath/filename'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But when I try the following syntax to insert a line at the BEGINNING of the file, it doesn't seem to work, i.e., nothing happens?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;x 'echo 'sed -i '1i "text you want to insert" &amp;gt;&amp;gt; filepath/filename'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any tips appreciated. Much thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 26 May 2020 14:33:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/X-COmmand-To-Modify-File/m-p/650775#M195173</guid>
      <dc:creator>shl007</dc:creator>
      <dc:date>2020-05-26T14:33:33Z</dc:date>
    </item>
    <item>
      <title>Re: X COmmand To Modify File?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/X-COmmand-To-Modify-File/m-p/650784#M195177</link>
      <description>&lt;P&gt;The complete commandline for the sed call is this:&lt;/P&gt;
&lt;PRE&gt;sed -i '1s/^/text you want to insert'\n' filepath/filename
&lt;/PRE&gt;
&lt;P&gt;So the SAS statements will be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x "sed -i '1s/^/text you want to insert on top'\n' filepath/filename";
x "echo 'text you want to insert at end' &amp;gt;&amp;gt; filepath/filename";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please also post the data step code you tried.&lt;/P&gt;</description>
      <pubDate>Tue, 26 May 2020 14:44:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/X-COmmand-To-Modify-File/m-p/650784#M195177</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-26T14:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: X COmmand To Modify File?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/X-COmmand-To-Modify-File/m-p/650838#M195193</link>
      <description>&lt;P&gt;Below is the data code I had tried. I am populating the filename with a macro variable set earlier (not shown). The file modification is working, just truncating certain lines for some reason.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename output pipe "ls -a /mypath/*myfile*";

%macro create_xml;

%if &amp;amp;totalfiles gt 0 %then %do;
%do i=1 %to &amp;amp;totalfiles;
	data _null_;

     infile "&amp;amp;&amp;amp;filenm&amp;amp;i" lrecl=32767 end = last;

/*	moddate=finfo(fid,'Last Modified');*/

	do while(not last);
    	input;

	    file "&amp;amp;&amp;amp;fileout&amp;amp;i";

		if lag("&amp;amp;&amp;amp;filenm&amp;amp;i") ne "&amp;amp;&amp;amp;filenm&amp;amp;i" then do;

        	put "mytext1"; /* beginning of file */

        end;

            put _infile_;  
	end;

	if  last then do;

       		put "&amp;lt;/root&amp;gt;";

	end;
 
run;
%end;
%end;
%mend create_xml;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 May 2020 16:48:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/X-COmmand-To-Modify-File/m-p/650838#M195193</guid>
      <dc:creator>shl007</dc:creator>
      <dc:date>2020-05-26T16:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: X COmmand To Modify File?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/X-COmmand-To-Modify-File/m-p/650840#M195194</link>
      <description>&lt;P&gt;Also, just to document what worked for me to insert the first line in file:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;x "sed -i '1i mytext' /mypath/myfile.txt";&lt;/P&gt;</description>
      <pubDate>Tue, 26 May 2020 16:51:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/X-COmmand-To-Modify-File/m-p/650840#M195194</guid>
      <dc:creator>shl007</dc:creator>
      <dc:date>2020-05-26T16:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: X COmmand To Modify File?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/X-COmmand-To-Modify-File/m-p/650868#M195204</link>
      <description>&lt;P&gt;Your data step code is much too complicated. Use mine as a blueprint.&lt;/P&gt;
&lt;P&gt;In particular, this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if lag("&amp;amp;&amp;amp;filenm&amp;amp;i") ne "&amp;amp;&amp;amp;filenm&amp;amp;i" then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;makes no sense, as lag cannot work with strings, only data step variables. It seems you tried to adapt code that reads filenames from a dataset and reads multiple files, but you only need to read and write a single file in one step.&lt;/P&gt;</description>
      <pubDate>Tue, 26 May 2020 18:03:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/X-COmmand-To-Modify-File/m-p/650868#M195204</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-26T18:03:53Z</dc:date>
    </item>
  </channel>
</rss>

