<?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: Difference between only IF with ; and IF with THEN statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-only-IF-with-and-IF-with-THEN-statement/m-p/245446#M45806</link>
    <description>&lt;P&gt;It's possible that I'm saying nothing new here ... just saying it differently.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you have observed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;FONT color="#FF6600"&gt;IF without THEN&lt;/FONT&gt; is totally different from &lt;FONT color="#0000FF"&gt;IF/THEN&lt;/FONT&gt;.&lt;/LI&gt;
&lt;LI&gt;&lt;FONT color="#FF6600"&gt;IF without THEN&lt;/FONT&gt; deletes observations.&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Using &lt;FONT color="#FF6600"&gt;IF without THEN&lt;/FONT&gt;, you would expect to find only observations having GRADES of "Grade1" or "Grade2". &amp;nbsp;All others would be deleted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using &lt;FONT color="#0000FF"&gt;IF/THEN&lt;/FONT&gt;, you would expect to find all the observations that appear in the incoming data. &amp;nbsp;However, the extra variables (NAME and TOTAL_MARKS) would be populated only for the "Grade1" and "Grade2" observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's perhaps unfortunate that both statements contain the word IF. &amp;nbsp;They have entirely different meanings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
    <pubDate>Fri, 22 Jan 2016 14:47:23 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-01-22T14:47:23Z</dc:date>
    <item>
      <title>Difference between only IF with ; and IF with THEN statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-only-IF-with-and-IF-with-THEN-statement/m-p/245441#M45802</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anybody explain the reason for, when the code colored &lt;FONT color="#FF6600"&gt;orange&lt;/FONT&gt; is executed it returns 5 records. Whereas code colored &lt;FONT color="#0000FF"&gt;blue&lt;/FONT&gt; is executed it returns all records i.e. 7 records (Name and TotalMarks are missing)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data ds_grade;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;infile cards;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;input grades $6. @;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;*BELOW IF RETURNS 5 RECORDS;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;FONT color="#FF6600"&gt;&lt;STRONG&gt;if grades = 'Grade1' or grades = 'Grade2';&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF6600"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;input name : $6. Total_Marks;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;*BELOW IF THEN RETURNS ALL 7 RECORDS BUT NAME AND MARKS FOR GRADE3 AND GRADE4 MISSING;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;/*&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;FONT color="#0000FF"&gt;&amp;nbsp;&lt;STRONG&gt;if grades = 'Grade1' or grades = 'Grade2' then &lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;input name : $6. Total_Marks;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;*/&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;cards;&lt;BR /&gt;Grade1 abcdef 500&lt;BR /&gt;Grade3 pqrstu 375&lt;BR /&gt;Grade1 xyz 510&lt;BR /&gt;Grade2 abc123 430&lt;BR /&gt;Grade2 eeeee 450&lt;BR /&gt;Grade4 hhhh 270&lt;BR /&gt;Grade1 jjjjjj 505&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;Anand&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2016 14:04:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-only-IF-with-and-IF-with-THEN-statement/m-p/245441#M45802</guid>
      <dc:creator>a_k93</dc:creator>
      <dc:date>2016-01-22T14:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between only IF with ; and IF with THEN statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-only-IF-with-and-IF-with-THEN-statement/m-p/245443#M45803</link>
      <description>&lt;P&gt;The first if statement you have operates like a where clause:&lt;/P&gt;
&lt;PRE&gt; if grades = 'Grade1' or grades = 'Grade2';
        input name : $6. Total_Marks;&lt;/PRE&gt;
&lt;P&gt;It is a bit like saying: only keep records where grades is Grade1 or Grade2. &amp;nbsp;Hence you get fewer records. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second if statement:&lt;/P&gt;
&lt;PRE&gt; if grades = 'Grade1' or grades = 'Grade2' then 
        input name : $6. Total_Marks;&lt;/PRE&gt;
&lt;P&gt;Is considered to be a conditional read. &amp;nbsp;I.e. every row is read in, but the input only reads the data elements into the variables if the grades is Grade1 or Grade2. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the first only records rows where the if is true, the second reads all rows, but populates variables only when the condition is true.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2016 14:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-only-IF-with-and-IF-with-THEN-statement/m-p/245443#M45803</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-01-22T14:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between only IF with ; and IF with THEN statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-only-IF-with-and-IF-with-THEN-statement/m-p/245444#M45804</link>
      <description>&lt;P&gt;The subsetting IF the one with NO THEN is like a gate. &amp;nbsp;When true the gate is closed and execution is "returned to the top of the implied data step loop".&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2016 14:33:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-only-IF-with-and-IF-with-THEN-statement/m-p/245444#M45804</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-01-22T14:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between only IF with ; and IF with THEN statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-only-IF-with-and-IF-with-THEN-statement/m-p/245445#M45805</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;The first if statement you have operates like a where clause:&lt;/P&gt;
&lt;PRE&gt; if grades = 'Grade1' or grades = 'Grade2';
        input name : $6. Total_Marks;&lt;/PRE&gt;
&lt;P&gt;It is a bit like saying: only keep records where grades is Grade1 or Grade2. &amp;nbsp;Hence you get fewer records. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That might be considered true in this example but subsetting&amp;nbsp;IF and WHERE should not be considered synonymous.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2016 14:36:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-only-IF-with-and-IF-with-THEN-statement/m-p/245445#M45805</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-01-22T14:36:51Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between only IF with ; and IF with THEN statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-only-IF-with-and-IF-with-THEN-statement/m-p/245446#M45806</link>
      <description>&lt;P&gt;It's possible that I'm saying nothing new here ... just saying it differently.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you have observed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;FONT color="#FF6600"&gt;IF without THEN&lt;/FONT&gt; is totally different from &lt;FONT color="#0000FF"&gt;IF/THEN&lt;/FONT&gt;.&lt;/LI&gt;
&lt;LI&gt;&lt;FONT color="#FF6600"&gt;IF without THEN&lt;/FONT&gt; deletes observations.&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Using &lt;FONT color="#FF6600"&gt;IF without THEN&lt;/FONT&gt;, you would expect to find only observations having GRADES of "Grade1" or "Grade2". &amp;nbsp;All others would be deleted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using &lt;FONT color="#0000FF"&gt;IF/THEN&lt;/FONT&gt;, you would expect to find all the observations that appear in the incoming data. &amp;nbsp;However, the extra variables (NAME and TOTAL_MARKS) would be populated only for the "Grade1" and "Grade2" observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's perhaps unfortunate that both statements contain the word IF. &amp;nbsp;They have entirely different meanings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2016 14:47:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-only-IF-with-and-IF-with-THEN-statement/m-p/245446#M45806</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-01-22T14:47:23Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between only IF with ; and IF with THEN statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-only-IF-with-and-IF-with-THEN-statement/m-p/245447#M45807</link>
      <description>&lt;P&gt;Thanks Guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But what is the practical use of 2nd if statment (IF/THEN) as it is returning 7 observation in current case? In what situation you will go for 2nd if condition.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2016 14:51:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-only-IF-with-and-IF-with-THEN-statement/m-p/245447#M45807</guid>
      <dc:creator>a_k93</dc:creator>
      <dc:date>2016-01-22T14:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between only IF with ; and IF with THEN statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-only-IF-with-and-IF-with-THEN-statement/m-p/245453#M45809</link>
      <description>&lt;P&gt;Typical use of the IF/THEN statement would be where:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You want all observations in the data set&lt;/LI&gt;
&lt;LI&gt;But the structure of the data is different for some.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;For example, how would you read in data that looked like this:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;cards;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Grade1 abcdef 500&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Grade3 No Data Available&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Grade1 xyz 510&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Grade2 abc123 430&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Grade2 eeeee 450&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Grade4 No Data Available&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Grade1 jjjjjj 505&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You woud want to read in NAME and TOTAL_MARKS, but that should only apply when GRADE is "Grade1" or "Grade2".&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2016 15:01:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-only-IF-with-and-IF-with-THEN-statement/m-p/245453#M45809</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-01-22T15:01:53Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between only IF with ; and IF with THEN statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-only-IF-with-and-IF-with-THEN-statement/m-p/245456#M45810</link>
      <description>Hi:&lt;BR /&gt;  Imagine that you have slightly different data and each row is for a different country. When the value for country is US, then you need to read the data line one way and when the value for country is UK, then you need to read the data line another way. &lt;BR /&gt;  &lt;BR /&gt;Imagine data like this:&lt;BR /&gt;US,John,Doe,$35000,yearly&lt;BR /&gt;UK,Smythe,George,annual,40000&lt;BR /&gt;US,Jane,Smith,$36000,yearly&lt;BR /&gt;US,Elle,Vator,$39000,yearly&lt;BR /&gt;UK,Windsor,Marge,annual,50000&lt;BR /&gt;   &lt;BR /&gt;and you need to read each record, but clearly, you need a different INPUT statement to be used for each country. That is when you would use IF...THEN, as in:&lt;BR /&gt;data readit;&lt;BR /&gt;  infile 'c:\temp\diffdata.txt' dlm=',' dsd;&lt;BR /&gt;  input country $ @;&lt;BR /&gt;  if country = 'US' then&lt;BR /&gt;    input first $ last $ sal : comma. type $;&lt;BR /&gt;  else if country = 'UK' then&lt;BR /&gt;    input last $ first $ type $ sal;&lt;BR /&gt;run;&lt;BR /&gt;    &lt;BR /&gt;proc print data=readit;&lt;BR /&gt;  var country last first sal type;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;cynthia</description>
      <pubDate>Fri, 22 Jan 2016 15:11:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-only-IF-with-and-IF-with-THEN-statement/m-p/245456#M45810</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2016-01-22T15:11:20Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between only IF with ; and IF with THEN statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-only-IF-with-and-IF-with-THEN-statement/m-p/245485#M45816</link>
      <description>&lt;P&gt;Thanks everybody for reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In short if we want to exclude few observation then we have to use if with semicolan,&amp;nbsp; but if we do not want to exclude any observation and take certain action basis certain condition than we use IF/THEN.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2016 16:32:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-only-IF-with-and-IF-with-THEN-statement/m-p/245485#M45816</guid>
      <dc:creator>a_k93</dc:creator>
      <dc:date>2016-01-22T16:32:25Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between only IF with ; and IF with THEN statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-only-IF-with-and-IF-with-THEN-statement/m-p/245502#M45820</link>
      <description>&lt;P&gt;In this instance think of:&lt;/P&gt;
&lt;P&gt;if &amp;lt;condition&amp;gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;as shorthand for:&lt;/P&gt;
&lt;P&gt;if &amp;lt;condition&amp;gt; then output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To be honest I would recommend the full text as it makes it clearer what it is doing, but thats just my preference.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2016 17:09:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-only-IF-with-and-IF-with-THEN-statement/m-p/245502#M45820</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-01-22T17:09:34Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between only IF with ; and IF with THEN statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-only-IF-with-and-IF-with-THEN-statement/m-p/245550#M45845</link>
      <description>&lt;P&gt;I think your example would only be true if&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;IF &amp;lt;condition&amp;gt; THEN OUTPUT;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is the very last statement in the dataset as subsetting IF has implied RETURN.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think it would be more accurate to say&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; IF &amp;lt;condition&amp;gt;;&lt;/P&gt;
&lt;P&gt;is similar in function to&lt;/P&gt;
&lt;P&gt;&amp;nbsp; IF not(&amp;lt;condition&amp;gt;) then delete;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Both DELETE and the subsetting IF have the implied RETURN.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2016 21:23:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-only-IF-with-and-IF-with-THEN-statement/m-p/245550#M45845</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-01-22T21:23:08Z</dc:date>
    </item>
  </channel>
</rss>

