<?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 output to a text file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-output-to-a-text-file/m-p/391782#M94180</link>
    <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Wed, 30 Aug 2017 11:18:40 GMT</pubDate>
    <dc:creator>BalajiBollu</dc:creator>
    <dc:date>2017-08-30T11:18:40Z</dc:date>
    <item>
      <title>How to write output to a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-output-to-a-text-file/m-p/391406#M93992</link>
      <description>&lt;P&gt;I just want an extended version of this output with two more variables.&amp;nbsp;Let's say I have the dataset like the below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;have;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;F1$ F2$ F2_1$ F4$ F4_1$ F4_2$ F3$ F5$;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Name1 RD 10 RS 1 2 AS GS&lt;/P&gt;&lt;P&gt;Name2 RD 20 RS 3 4 AS TS&lt;/P&gt;&lt;P&gt;Name2 RD 20 RS 5 6 AS TT&lt;/P&gt;&lt;P&gt;Name2 RD 20 RS 7 8 AS ST&lt;/P&gt;&lt;P&gt;Name3 RD 30 RS 11 12 AS GS&lt;/P&gt;&lt;P&gt;Name3 RD 30 RS 13 14 AS HG&lt;/P&gt;&lt;P&gt;Name4 RD 40 RS 15 16 AS GS&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to get an output like the below. There is one more variable which has more than one value for one Name and that the order is also changed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Name1&lt;BR /&gt;RD|10&lt;BR /&gt;RS|1|2&lt;BR /&gt;AS&lt;/P&gt;&lt;P&gt;GS&lt;BR /&gt;Name2&lt;BR /&gt;RD|20&lt;BR /&gt;RS|3|4&lt;BR /&gt;RS|5|6&lt;BR /&gt;RS|7|8&lt;BR /&gt;AS&lt;/P&gt;&lt;P&gt;TS&lt;/P&gt;&lt;P&gt;TT&lt;/P&gt;&lt;P&gt;ST&lt;BR /&gt;Name3&lt;BR /&gt;RD|30&lt;BR /&gt;RS|11|12&lt;BR /&gt;RS|13|14&lt;BR /&gt;AS&lt;/P&gt;&lt;P&gt;GS&lt;/P&gt;&lt;P&gt;HG&lt;BR /&gt;Name4&lt;BR /&gt;RD|40&lt;BR /&gt;RS|15|16&lt;BR /&gt;AS&lt;/P&gt;&lt;P&gt;GS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 07:45:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-output-to-a-text-file/m-p/391406#M93992</guid>
      <dc:creator>BalajiBollu</dc:creator>
      <dc:date>2017-08-29T07:45:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to write output to a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-output-to-a-text-file/m-p/391408#M93994</link>
      <description>&lt;P&gt;Can you describe to transforming logic?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are F2 and F2_1 always the same for one F1?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 08:06:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-output-to-a-text-file/m-p/391408#M93994</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2017-08-29T08:06:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to write output to a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-output-to-a-text-file/m-p/391409#M93995</link>
      <description>&lt;P&gt;Well, this is really ugly code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input F1$ F2$ F2_1$ F4$ F4_1$ F4_2$ F3$ F5$;
datalines;
Name1 RD 10 RS 1 2 AS GS
Name2 RD 20 RS 3 4 AS TS
Name2 RD 20 RS 5 6 AS TT
Name2 RD 20 RS 7 8 AS ST
Name3 RD 30 RS 11 12 AS GS
Name3 RD 30 RS 13 14 AS HG
Name4 RD 40 RS 15 16 AS GS
;
run;

data _null_;
   set have;
   by F1;
   file "&amp;amp;Benutzer\narf.txt";

   length line buffer3 buffer5 $ 200;
   retain buffer:;

   array buffs[2] buffer3 buffer5;

   if first.F1 then do;
      call missing(of buffer:);
      put F1;

      line = catx('|', F2, F2_1);
      put line;
   end;

   line = catx('|', of F4:);
   put line;

   if not find(buffer3, F3) then do;
      buffer3 = catx(' ', buffer3, F3);
   end;

   if not find(buffer5, F5) then do;
      buffer5 = catx(' ', buffer5, F5);
   end;

   if last.F1 then do;
      do b = 1 to dim(buffs);
         do i = 1 to countw(buffs[b]);
            line = scan(buffs[b], i, ' ');
            put line;
         end;
      end;
   end;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Aug 2017 08:10:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-output-to-a-text-file/m-p/391409#M93995</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2017-08-29T08:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to write output to a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-output-to-a-text-file/m-p/391413#M93998</link>
      <description>&lt;P&gt;Yes F2 and F2_1 will have only one value for one F1 Value. Only F4 F4_1 F4_2 and F5 will have more than one value for one F1.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 08:42:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-output-to-a-text-file/m-p/391413#M93998</guid>
      <dc:creator>BalajiBollu</dc:creator>
      <dc:date>2017-08-29T08:42:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to write output to a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-output-to-a-text-file/m-p/391424#M94000</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/160863"&gt;@BalajiBollu&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Something like below might do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input F1$ F2$ F2_1$ F4$ F4_1$ F4_2$ F3$ F5$;
  datalines;
Name1 RD 10 RS 1 2 AS GS
Name2 RD 20 RS 3 4 AS TS
Name2 RD 20 RS 5 6 AS TT
Name2 RD 20 RS 7 8 AS ST
Name3 RD 30 RS 11 12 AS GS
Name3 RD 30 RS 13 14 AS HG
Name4 RD 40 RS 15 16 AS GS
;
run;

data _null_;
  if _n_=1 then
    do;
      length order 8 String $32;
      dcl hash h1(ordered:'y');
      h1.defineKey('F1','order','String');
      h1.defineData('String');
      h1.defineDone();
      call missing(of _all_);
    end;

  set have end=last;

  order=1; String=F1; 
  h1.ref();
  order=2; String=catx('|',of F2:); 
  h1.ref();
  order=3; String=catx('|',of F4:); 
  h1.ref();
  order=4; String=F3; 
  h1.ref();
  order=5; String=F5; 
  h1.ref();

  if last then h1.output(dataset:'want(keep=String)');
run;

data _null_;
  file print;
  set want;
  put String;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Aug 2017 10:58:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-output-to-a-text-file/m-p/391424#M94000</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-08-29T10:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to write output to a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-output-to-a-text-file/m-p/391446#M94007</link>
      <description>&lt;P&gt;How about this one ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input F1$ F2$ F2_1$ F4$ F4_1$ F4_2$ F3$ F5$;
datalines;
Name1 RD 10 RS 1 2 AS GS
Name2 RD 20 RS 3 4 AS TS
Name2 RD 20 RS 5 6 AS TT
Name2 RD 20 RS 7 8 AS ST
Name3 RD 30 RS 11 12 AS GS
Name3 RD 30 RS 13 14 AS HG
Name4 RD 40 RS 15 16 AS GS
;

filename x temp;
data _null_;
 file x;
 length x y $ 20000;
 do i=1 by 1 until(last.f2_1);
   set have;
   by f1 f2 f2_1;
   x= catx(',',x,catx('|',F4,F4_1,F4_2));
   if i=1 then y=catx(',',y,F3,F5);
     else y=catx(',',y,F5);
 end; 
 put F1;
 put F2 +(-1) '|'  F2_1;
 do i=1 to countw(x,',');
  temp=scan(x,i,',');
  put temp; 
 end;
 do i=1 to countw(y,',');
  temp=scan(y,i,',');
  put temp;
 end;
 run;

 data _null_;
  infile x;
  input;
  put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 12:46:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-output-to-a-text-file/m-p/391446#M94007</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-08-29T12:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to write output to a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-output-to-a-text-file/m-p/391781#M94179</link>
      <description>&lt;P&gt;Thanks much!!!&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 11:18:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-output-to-a-text-file/m-p/391781#M94179</guid>
      <dc:creator>BalajiBollu</dc:creator>
      <dc:date>2017-08-30T11:18:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to write output to a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-output-to-a-text-file/m-p/391782#M94180</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 11:18:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-output-to-a-text-file/m-p/391782#M94180</guid>
      <dc:creator>BalajiBollu</dc:creator>
      <dc:date>2017-08-30T11:18:40Z</dc:date>
    </item>
  </channel>
</rss>

