<?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: Multiple Output Statements within a Single Data Step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multiple-Output-Statements-within-a-Single-Data-Step/m-p/413377#M101157</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/41940"&gt;@kisumsam&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi there, I have a question about multiple output statements within a data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TWO;
input x y;
datalines;
5 2
3 1
5 6
;
RUN;

data ONE TWO OTHER;
set TWO;
if X eq 5 then output ONE;
if Y lt 5 then output TWO;
output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code above seems fairly straightforward. However, when I'm looking at the ONE data set, the order of the observations seems to be a little strange:&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="image 1.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16618i9E364265D83EF3FE/image-size/large?v=v2&amp;amp;px=999" role="button" title="image 1.png" alt="image 1.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am expecting the combined data set to be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;5 2&lt;BR /&gt;5 6&lt;/P&gt;
&lt;P&gt;5 2&lt;BR /&gt;3 1&lt;BR /&gt;5 6&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anyone know how the data set is sorted when we have the two output statements in the data step?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;To get that specific result one way would be:&lt;/P&gt;
&lt;PRE&gt;data three;
   set TWO (where=(x ge 5))
       two
   ;
run;&lt;/PRE&gt;
&lt;P&gt;which reads set two twice, the first bit says to keep only the records with x ge 5 and since that is the first input set they are output first,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;then read set two again with all records.&lt;/P&gt;</description>
    <pubDate>Tue, 14 Nov 2017 15:33:18 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-11-14T15:33:18Z</dc:date>
    <item>
      <title>Multiple Output Statements within a Single Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-Output-Statements-within-a-Single-Data-Step/m-p/413259#M101126</link>
      <description>&lt;P&gt;Hi there, I have a question about multiple output statements within a data step:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TWO;
input x y;
datalines;
5 2
3 1
5 6
;
RUN;

data ONE TWO OTHER;
set TWO;
if X eq 5 then output ONE;
if Y lt 5 then output TWO;
output;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code above seems fairly straightforward. However, when I'm looking at the ONE data set, the order of the observations seems to be a little strange:&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="image 1.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16618i9E364265D83EF3FE/image-size/large?v=v2&amp;amp;px=999" role="button" title="image 1.png" alt="image 1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From the first output statement, the first two observations should be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;5 2&lt;/P&gt;&lt;P&gt;5 6&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From the last output statement, the last three observations should be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;5 2&lt;BR /&gt;3 1&lt;BR /&gt;5 6&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am expecting the combined data set to be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;5 2&lt;BR /&gt;5 6&lt;/P&gt;&lt;P&gt;5 2&lt;BR /&gt;3 1&lt;BR /&gt;5 6&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, the order of the output data set is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The order of the data set is changed but it wasn't exactly sorted by X and Y.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know how the data set is sorted when we have the two output statements in the data step?&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 10:25:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-Output-Statements-within-a-Single-Data-Step/m-p/413259#M101126</guid>
      <dc:creator>kisumsam</dc:creator>
      <dc:date>2017-11-14T10:25:33Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Output Statements within a Single Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-Output-Statements-within-a-Single-Data-Step/m-p/413260#M101127</link>
      <description>&lt;P&gt;First the data step reads the observation 5 2. Then it checks if X eq 5, which is true, so it outputs to the data set ONE. next it checks if Y lt 5, which is false, so nothing is outputted. Next you simply have an output statement, which means that the 5 2 observations is outputted again(to all created data sets, including X). That is why the first two observations are 5 2.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 10:32:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-Output-Statements-within-a-Single-Data-Step/m-p/413260#M101127</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-11-14T10:32:52Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Output Statements within a Single Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-Output-Statements-within-a-Single-Data-Step/m-p/413377#M101157</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/41940"&gt;@kisumsam&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi there, I have a question about multiple output statements within a data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TWO;
input x y;
datalines;
5 2
3 1
5 6
;
RUN;

data ONE TWO OTHER;
set TWO;
if X eq 5 then output ONE;
if Y lt 5 then output TWO;
output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code above seems fairly straightforward. However, when I'm looking at the ONE data set, the order of the observations seems to be a little strange:&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="image 1.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16618i9E364265D83EF3FE/image-size/large?v=v2&amp;amp;px=999" role="button" title="image 1.png" alt="image 1.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am expecting the combined data set to be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;5 2&lt;BR /&gt;5 6&lt;/P&gt;
&lt;P&gt;5 2&lt;BR /&gt;3 1&lt;BR /&gt;5 6&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anyone know how the data set is sorted when we have the two output statements in the data step?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;To get that specific result one way would be:&lt;/P&gt;
&lt;PRE&gt;data three;
   set TWO (where=(x ge 5))
       two
   ;
run;&lt;/PRE&gt;
&lt;P&gt;which reads set two twice, the first bit says to keep only the records with x ge 5 and since that is the first input set they are output first,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;then read set two again with all records.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 15:33:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-Output-Statements-within-a-Single-Data-Step/m-p/413377#M101157</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-11-14T15:33:18Z</dc:date>
    </item>
  </channel>
</rss>

