<?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: DIIFFERNECE between if then output; AND if ; output; in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DIIFFERNECE-between-if-then-output-AND-if-output/m-p/675070#M203344</link>
    <description>&lt;P&gt;Do you want to output ALL of the non-missing values?&amp;nbsp; TEST1 will stop as soon as any value is missing.&amp;nbsp; That is because the subsetting IF statement stop the current iteration, which in this case stops the DO loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More complex test data will make this difference clearer in the output;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
  input id height1-height3;
cards;
0 100 101 102
1 .   104 105
2 .   .   108
3 .   .   . 
4 112 .   .
5 115 116 .
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;TEST1
Obs    id    height1    height2    height3    coding

 1      0      100        101        102        100
 2      0      100        101        102        101
 3      0      100        101        102        102
 4      4      112          .          .        112
 5      5      115        116          .        115
 6      5      115        116          .        116
&amp;#12;
TEST2
Obs    id    height1    height2    height3    coding

 1      0      100        101        102        100
 2      0      100        101        102        101
 3      0      100        101        102        102
 4      1        .        104        105        104
 5      1        .        104        105        105
 6      2        .          .        108        108
 7      4      112          .          .        112
 8      5      115        116          .        115
 9      5      115        116          .        116
&lt;/PRE&gt;</description>
    <pubDate>Thu, 06 Aug 2020 16:54:20 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-08-06T16:54:20Z</dc:date>
    <item>
      <title>DIIFFERNECE between if then output; AND if ; output;</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DIIFFERNECE-between-if-then-output-AND-if-output/m-p/675050#M203334</link>
      <description>&lt;P&gt;I have data like:&lt;/P&gt;&lt;P&gt;ID height1&amp;nbsp;height2&amp;nbsp;height3&lt;/P&gt;&lt;P&gt;1 100 101 102&lt;/P&gt;&lt;P&gt;2 103 104 105&lt;/P&gt;&lt;P&gt;3 . 102 103&lt;/P&gt;&lt;P&gt;4 104 . 106&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For code A, those observations after missing values cannot be output. But code B works. Can someone helps me explain it why? THX.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code A:&lt;/P&gt;&lt;P&gt;Data test1;&lt;BR /&gt;Set example;&lt;BR /&gt;Array DA height:;&lt;BR /&gt;Do over DA;&lt;BR /&gt;coding=DA;&lt;BR /&gt;&lt;STRONG&gt;if NOT missing(coding);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;output;&lt;/STRONG&gt;&lt;BR /&gt;End;&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code B:&lt;/P&gt;&lt;P&gt;Data test2;&lt;BR /&gt;Set example;&lt;BR /&gt;Array DA height:;&lt;BR /&gt;Do over DA;&lt;BR /&gt;coding=DA;&lt;BR /&gt;&lt;STRONG&gt;if NOT missing(coding) then&amp;nbsp;&lt;/STRONG&gt;&lt;STRONG&gt;output;&lt;/STRONG&gt;&lt;BR /&gt;End;&lt;BR /&gt;Run;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 16:09:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DIIFFERNECE-between-if-then-output-AND-if-output/m-p/675050#M203334</guid>
      <dc:creator>MillerMac</dc:creator>
      <dc:date>2020-08-06T16:09:50Z</dc:date>
    </item>
    <item>
      <title>Re: DIIFFERNECE between if then output; AND if ; output;</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DIIFFERNECE-between-if-then-output-AND-if-output/m-p/675056#M203337</link>
      <description>&lt;P&gt;The first code example is a "subsetting if". It basically means that ONLY the records that pass the if condition are kept. So as soon as one of the missing values is encountered the RECORD is discarded from further processing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second is a conditional output statement and writes to the output set when true.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 16:17:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DIIFFERNECE-between-if-then-output-AND-if-output/m-p/675056#M203337</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-08-06T16:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: DIIFFERNECE between if then output; AND if ; output;</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DIIFFERNECE-between-if-then-output-AND-if-output/m-p/675065#M203342</link>
      <description>&lt;P&gt;The subsetting if jumps immediately to the "top" of the data step and starts the next iteration; the IF THEN OUTPUT makes only the output conditional, but will still execute all following statements in the current iteration.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See this code example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x1;
datalines;
1
2
3
4
5
;

data want1;
set have;
if x1 ne 4 then output;
x2 + 1;
run;

data want2;
set have;
if x1 ne 4;
x2 + 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Aug 2020 16:34:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DIIFFERNECE-between-if-then-output-AND-if-output/m-p/675065#M203342</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-06T16:34:37Z</dc:date>
    </item>
    <item>
      <title>Re: DIIFFERNECE between if then output; AND if ; output;</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DIIFFERNECE-between-if-then-output-AND-if-output/m-p/675070#M203344</link>
      <description>&lt;P&gt;Do you want to output ALL of the non-missing values?&amp;nbsp; TEST1 will stop as soon as any value is missing.&amp;nbsp; That is because the subsetting IF statement stop the current iteration, which in this case stops the DO loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More complex test data will make this difference clearer in the output;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
  input id height1-height3;
cards;
0 100 101 102
1 .   104 105
2 .   .   108
3 .   .   . 
4 112 .   .
5 115 116 .
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;TEST1
Obs    id    height1    height2    height3    coding

 1      0      100        101        102        100
 2      0      100        101        102        101
 3      0      100        101        102        102
 4      4      112          .          .        112
 5      5      115        116          .        115
 6      5      115        116          .        116
&amp;#12;
TEST2
Obs    id    height1    height2    height3    coding

 1      0      100        101        102        100
 2      0      100        101        102        101
 3      0      100        101        102        102
 4      1        .        104        105        104
 5      1        .        104        105        105
 6      2        .          .        108        108
 7      4      112          .          .        112
 8      5      115        116          .        115
 9      5      115        116          .        116
&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Aug 2020 16:54:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DIIFFERNECE-between-if-then-output-AND-if-output/m-p/675070#M203344</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-06T16:54:20Z</dc:date>
    </item>
  </channel>
</rss>

