<?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 Can one write to two text files in one data step? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-one-write-to-two-text-files-in-one-data-step/m-p/742928#M232494</link>
    <description>&lt;P&gt;Can one write to two, or more,&amp;nbsp; text files using one data step?&amp;nbsp; I cannot Google this anywhere, here or elsewhere?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 21 May 2021 15:36:43 GMT</pubDate>
    <dc:creator>PhilC</dc:creator>
    <dc:date>2021-05-21T15:36:43Z</dc:date>
    <item>
      <title>Can one write to two text files in one data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-one-write-to-two-text-files-in-one-data-step/m-p/742928#M232494</link>
      <description>&lt;P&gt;Can one write to two, or more,&amp;nbsp; text files using one data step?&amp;nbsp; I cannot Google this anywhere, here or elsewhere?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 15:36:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-one-write-to-two-text-files-in-one-data-step/m-p/742928#M232494</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-05-21T15:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: Can one write to two text files in one data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-one-write-to-two-text-files-in-one-data-step/m-p/742932#M232498</link>
      <description>&lt;P&gt;I'd simply try it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set sashelp.class;
file "t1.csv" dlm=",";
put name sex age height weight;
file "t2.csv" dlm=",";
put name sex age height weight;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 May 2021 15:42:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-one-write-to-two-text-files-in-one-data-step/m-p/742932#M232498</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-05-21T15:42:32Z</dc:date>
    </item>
    <item>
      <title>Re: Can one write to two text files in one data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-one-write-to-two-text-files-in-one-data-step/m-p/742940#M232501</link>
      <description>&lt;P&gt;You answered the question.&amp;nbsp; So then I change it. (sorry)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IF you are writing more than one text file and you want the file to be named by a SAS run-time variable, we can't do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set sashelp.class;
  fname=catt(put(age,z2.),".csv");
  file fname dlm=",";
    put name sex age height weight;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How do I save to file named in var FNAME?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I should have mentioned Fopen() and other statements.&amp;nbsp; I did not anticipate your simple solution.&amp;nbsp; It adds to my knowledge.&amp;nbsp; I know I can use a select statement with that solution, but I was really curious about how to avoiding a select statement.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 16:15:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-one-write-to-two-text-files-in-one-data-step/m-p/742940#M232501</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-05-21T16:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: Can one write to two text files in one data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-one-write-to-two-text-files-in-one-data-step/m-p/742958#M232508</link>
      <description>&lt;P&gt;My RL program is needing me to write ~150 text files.&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 16:44:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-one-write-to-two-text-files-in-one-data-step/m-p/742958#M232508</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-05-21T16:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: Can one write to two text files in one data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-one-write-to-two-text-files-in-one-data-step/m-p/742987#M232524</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15329"&gt;@PhilC&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;My RL program is needing me to write ~150 text files.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Details help.&lt;/P&gt;
&lt;P&gt;How do you know when to write to which file?&lt;/P&gt;
&lt;P&gt;Do they all getthe same variables?&lt;/P&gt;
&lt;P&gt;What format is the "text file"? Fixed column, delimited or what?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think that you want to look at the FILEVAR option on the File statement.&lt;/P&gt;
&lt;P&gt;Suggest that you use a full path in the name of the file.&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set sashelp.class;
  outname=catt("D:\Users\Owner\Documents\",put(age,z2.),".csv");
  file dummy filevar=outname dlm=",";
  put name sex age height weight;

run;
&lt;/PRE&gt;
&lt;P&gt;In this case the "fileref" dummy is basically a placeholder as it uses the text of the Filevar=variable for the file name.&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 17:42:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-one-write-to-two-text-files-in-one-data-step/m-p/742987#M232524</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-21T17:42:16Z</dc:date>
    </item>
    <item>
      <title>Re: Can one write to two text files in one data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-one-write-to-two-text-files-in-one-data-step/m-p/743011#M232535</link>
      <description>&lt;P&gt;right, not "dummy" because I didn't write out my details.&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yet -- This was what I needed.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My RL code executes like this, within the context of our SASHELP.CLASS&amp;nbsp; example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.class out=class;
  by Age;
data _null_;
  do until (eof);
    set class end=eof;
      by Age;
    if first.Age then do;
      length fname $200;
        retain fname;
        fname=catt(put(age,z2.),".csv");
      file dummy filevar=Fname dlm=",";
      end;
    put name sex age height weight;
  end;
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I didn't need headers in my RL code, so there are none here.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks Kurt,&lt;/P&gt;
&lt;P&gt;Thanks Ballardw,&lt;/P&gt;
&lt;P&gt;you are like SAS gods to me.&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 18:58:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-one-write-to-two-text-files-in-one-data-step/m-p/743011#M232535</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-05-21T18:58:41Z</dc:date>
    </item>
  </channel>
</rss>

