<?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: Write to file from data step. in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Write-to-file-from-data-step/m-p/95751#M27111</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not really sure what you are trying to do, but think you are over-complicating the process.&amp;nbsp; Are you just trying to do something like?:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data _null_;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; file "C:...\file.txt";&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put "txttxt";&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 16 Aug 2012 13:50:33 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2012-08-16T13:50:33Z</dc:date>
    <item>
      <title>Write to file from data step.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Write-to-file-from-data-step/m-p/95750#M27110</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I need dynamically create files and fill them by needed text in datastep, example of code below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; filePath="C:...\file.txt";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc1=filename("newFile",filePath);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fid=fopen("newFile","A");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put "txttxt";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rcClose=fclose(fid);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;File creates(with zero length) but file content is missing, instead "txttxt" text writes to SAS log.&lt;/P&gt;&lt;P&gt;Factually put statament write text not into created file but to SAS log.&lt;/P&gt;&lt;P&gt;So how can I write needed text into the file?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Aug 2012 12:54:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Write-to-file-from-data-step/m-p/95750#M27110</guid>
      <dc:creator>Yura2301</dc:creator>
      <dc:date>2012-08-16T12:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: Write to file from data step.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Write-to-file-from-data-step/m-p/95751#M27111</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not really sure what you are trying to do, but think you are over-complicating the process.&amp;nbsp; Are you just trying to do something like?:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data _null_;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; file "C:...\file.txt";&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put "txttxt";&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Aug 2012 13:50:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Write-to-file-from-data-step/m-p/95751#M27111</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-08-16T13:50:33Z</dc:date>
    </item>
    <item>
      <title>Re: Write to file from data step.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Write-to-file-from-data-step/m-p/95752#M27112</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Artur,&lt;/P&gt;&lt;P&gt;I should generate filename "on fly" depends on value from input dataset.&lt;/P&gt;&lt;P&gt;So if you will try example similar to your but with small change:&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;data _null_;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; path="C:...\file.txt";&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; file path;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put "txttxt";&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;It will not work becouse filename in file statement should be predefined before dataset...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Aug 2012 13:55:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Write-to-file-from-data-step/m-p/95752#M27112</guid>
      <dc:creator>Yura2301</dc:creator>
      <dc:date>2012-08-16T13:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: Write to file from data step.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Write-to-file-from-data-step/m-p/95753#M27113</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yura,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some of the other details of the problem might be important here.&amp;nbsp; Think about these possibilities.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you use two DATA steps instead of one?&amp;nbsp; The first one captures the destination file as a macro variable.&amp;nbsp; The second one uses the macro variable in the FILE statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Are you writing to just one file per DATA step?&amp;nbsp; You might be able to define a temporary file as the path:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;file 'C:.../temp.txt';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then have the DATA step generate a system command to copy temp.txt to the real destination, and another system command to delete temp.txt.&amp;nbsp; You would probably use CALL EXECUTE to do that, something along the lines of:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if eof then call execute('x copy temp.txt ' || true_destination || '; x delete temp.txt;');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are definitely some details to work out (syntax for the system commands, where to add quotes within it).&amp;nbsp; It's wasteful if the files are large, but it wasn't clear from your example if they were large or small.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Aug 2012 14:08:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Write-to-file-from-data-step/m-p/95753#M27113</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-08-16T14:08:25Z</dc:date>
    </item>
    <item>
      <title>Re: Write to file from data step.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Write-to-file-from-data-step/m-p/95754#M27114</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Like Astounding suggested, call execute is definitely one way of doing what I think you are trying to accomplish.&amp;nbsp; e.g.:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; informat file_path text_to_write $50.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input file_path text_to_write &amp;amp;;&lt;/P&gt;&lt;P&gt;&amp;nbsp; call execute(&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'data _null_; file "'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ||strip(file_path)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ||'"; put "'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ||text_to_write&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ||'"; run;'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; );&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;c:\test1.txt&amp;nbsp;&amp;nbsp; this is a test&lt;/P&gt;&lt;P&gt;c:\test2.txt&amp;nbsp;&amp;nbsp; some other text&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Aug 2012 14:30:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Write-to-file-from-data-step/m-p/95754#M27114</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-08-16T14:30:08Z</dc:date>
    </item>
    <item>
      <title>Re: Write to file from data step.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Write-to-file-from-data-step/m-p/95755#M27115</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&amp;nbsp; &lt;SPAN class="j-post-author "&gt;&lt;STRONG&gt;&lt;A _jive_internal="true" class="jiveTT-hover-user jive-username-link" data-avatarid="-1" data-externalid="" data-presence="null" data-userid="5253" data-username="Astounding" href="https://communities.sas.com/people/Astounding" id="jive-525345614845838010803"&gt;Astounding&lt;/A&gt; &lt;/STRONG&gt;&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;I should write many files from datastep.&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author "&gt;&lt;/SPAN&gt;Offcource I can use few data step or some macro with loop and then file statement for each created file, but it will increaze execution time, and it is critical...&lt;/P&gt;&lt;P&gt;In real task I should create ~20-30 files each time from one datastep.&lt;/P&gt;&lt;P&gt;May be these functions - fopen fclose etc. were created just for managing(delete,create files) but in this case why it( fopen func) has ,for example, 'A'(append) prameter( modifier) if there is no possibility wite from same datastep into this file...&lt;/P&gt;&lt;P&gt;Should be some possibility route any text into created from same data step file(I hope so)...&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Aug 2012 14:31:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Write-to-file-from-data-step/m-p/95755#M27115</guid>
      <dc:creator>Yura2301</dc:creator>
      <dc:date>2012-08-16T14:31:28Z</dc:date>
    </item>
    <item>
      <title>Re: Write to file from data step.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Write-to-file-from-data-step/m-p/95756#M27116</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Arthur,&lt;/P&gt;&lt;P&gt;Thanks, it's what I need!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Aug 2012 14:39:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Write-to-file-from-data-step/m-p/95756#M27116</guid>
      <dc:creator>Yura2301</dc:creator>
      <dc:date>2012-08-16T14:39:38Z</dc:date>
    </item>
    <item>
      <title>Re: Write to file from data step.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Write-to-file-from-data-step/m-p/95757#M27117</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is easy to dynamically select the filename to write to using the FILEVAR option on the FILE statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set sashelp.class;&lt;/P&gt;&lt;P&gt;&amp;nbsp; filename = catx('\','c:\temp',catx('.',sex,'txt'));&lt;/P&gt;&lt;P&gt;&amp;nbsp; file out filevar=filename;&lt;/P&gt;&lt;P&gt;&amp;nbsp; put name;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;C:\temp&amp;gt;more F.txt&lt;/P&gt;&lt;P&gt;Joyce&lt;/P&gt;&lt;P&gt;Judy&lt;/P&gt;&lt;P&gt;Louise&lt;/P&gt;&lt;P&gt;Mary&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;C:\temp&amp;gt;more M.txt&lt;/P&gt;&lt;P&gt;Philip&lt;/P&gt;&lt;P&gt;Robert&lt;/P&gt;&lt;P&gt;Ronald&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;P&gt;William&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Aug 2012 15:21:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Write-to-file-from-data-step/m-p/95757#M27117</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-08-16T15:21:28Z</dc:date>
    </item>
    <item>
      <title>Re: Write to file from data step.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Write-to-file-from-data-step/m-p/95758#M27118</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;Thanks, it also works, looks like it is the most qucik solution.&lt;/P&gt;&lt;P&gt;I have one more small issue, if few times write put statement it obviosly write text into two separate lines, but I need store them into one line, for example:&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set sashelp.class;&lt;/P&gt;&lt;P&gt;&amp;nbsp; filename = catx('\','c:\temp',catx('.',sex,'txt'));&lt;/P&gt;&lt;P&gt;&amp;nbsp; file out filevar=filename;&lt;/P&gt;&lt;P&gt;&amp;nbsp; put "txt1";&lt;/P&gt;&lt;P&gt;&amp;nbsp; put "txt2";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;And result in file will be :&lt;/P&gt;&lt;P&gt;txt1&lt;/P&gt;&lt;P&gt;txt2&lt;/P&gt;&lt;P&gt;But I need "txt1txt2".&lt;/P&gt;&lt;P&gt;So may be you also know how to write all these lines into one file row?&lt;/P&gt;&lt;P&gt;Concatenations two needed character variables isn't ok in&amp;nbsp; my case becouse they summury length can be more then 32767...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Aug 2012 15:40:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Write-to-file-from-data-step/m-p/95758#M27118</guid>
      <dc:creator>Yura2301</dc:creator>
      <dc:date>2012-08-16T15:40:14Z</dc:date>
    </item>
    <item>
      <title>Re: Write to file from data step.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Write-to-file-from-data-step/m-p/95759#M27119</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yura,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I agree that the solution Tom offered is definitely the easiest one.&amp;nbsp; As for your latest question, just use an @ symbol in your put statement.&amp;nbsp; e.g.,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt; put "txt1" @;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt; put "txt2";&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Aug 2012 15:43:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Write-to-file-from-data-step/m-p/95759#M27119</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-08-16T15:43:09Z</dc:date>
    </item>
    <item>
      <title>Re: Write to file from data step.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Write-to-file-from-data-step/m-p/95760#M27120</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi again Arthur,&lt;/P&gt;&lt;P&gt;It also works.&lt;/P&gt;&lt;P&gt;Thanks a lot for help guys!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Aug 2012 15:48:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Write-to-file-from-data-step/m-p/95760#M27120</guid>
      <dc:creator>Yura2301</dc:creator>
      <dc:date>2012-08-16T15:48:25Z</dc:date>
    </item>
  </channel>
</rss>

