<?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: IF/THEN questions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-questions/m-p/842788#M333253</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/431484"&gt;@Nietzsche&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi I am currently on page 133 of the official Specialist Prep Guide.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Two things I wish to confirm with the community because book does not explain it regarding to IF/THEN (maybe in later chapters).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First:&amp;nbsp; is IF first.dept the same thing as if first.dept=1 or if first.dept=TRUE? SAS assumes that user mean true (like in python)?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes.&amp;nbsp; Do you know WHY ?&amp;nbsp; &amp;nbsp;Do you know what result SAS returns from the evaluation of a boolean expression (such as first.dept=1) ?&amp;nbsp; &amp;nbsp;Do you know what truth value SAS uses when given a number like 1 to interpret as a boolean?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hint remember that SAS has only two types of variables.&amp;nbsp; Fixed length character strings and floating point numbers.&lt;/P&gt;
&lt;LI-SPOILER&gt;The result of a boolean expression is either 1 (true) or 0 (false).&lt;BR /&gt;&lt;BR /&gt;Zero or missing is considered FALSE.&amp;nbsp; Any other value is considered TRUE.&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Secondly: if nothing is stated after the IF statement like IF last.dept; it just means end everything the IF statement?&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Sort of.&amp;nbsp; They are actually two different statements.&amp;nbsp; Without the THEN you have a &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p1cxl8ifdt8u0gn12wqbji8o5fq1.htm" target="_self"&gt;SUBSETTING IF&lt;/A&gt;&amp;nbsp;statement instead.&amp;nbsp; Basically if the condition is not true this particular iteration of the data step stops immediately.&amp;nbsp; So statements after that are not executed. Note this includes any implied OUTPUT statement that might be executed when the iteration reaches the end of the data step code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 06 Nov 2022 21:40:20 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-11-06T21:40:20Z</dc:date>
    <item>
      <title>IF/THEN questions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-questions/m-p/842784#M333250</link>
      <description>&lt;P&gt;Hi I am currently on page 133 of the official Specialist Prep Guide.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Two things I wish to confirm with the community because book does not explain it regarding to IF/THEN (maybe in later chapters).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First:&amp;nbsp; is IF first.dept the same thing as if first.dept=1 or if first.dept=TRUE? SAS assumes that user mean true (like in python)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Secondly: if nothing is stated after the IF statement like IF last.dept; it just means end everything the IF statement?&amp;nbsp;&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;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Nietzsche_0-1667767303052.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77010i3B795F7B82202F7F/image-size/large?v=v2&amp;amp;px=999" role="button" title="Nietzsche_0-1667767303052.png" alt="Nietzsche_0-1667767303052.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Nov 2022 20:46:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-questions/m-p/842784#M333250</guid>
      <dc:creator>Nietzsche</dc:creator>
      <dc:date>2022-11-06T20:46:02Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN questions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-questions/m-p/842786#M333251</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Case 1, SAS treats zero (0) and missing numeric values (.) as False, all other (numbers) are treated as True, see:&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/p1n8bsqqd03xppn17pgvjpjlbhhs.htm#n09r5v4g2s15tun1mpslch1iehxh" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/p1n8bsqqd03xppn17pgvjpjlbhhs.htm#n09r5v4g2s15tun1mpslch1iehxh&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Case 2, it is the IF-subsetting, see here:&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p1cxl8ifdt8u0gn12wqbji8o5fq1.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p1cxl8ifdt8u0gn12wqbji8o5fq1.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Sun, 06 Nov 2022 21:35:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-questions/m-p/842786#M333251</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-11-06T21:35:20Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN questions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-questions/m-p/842787#M333252</link>
      <description>&lt;P&gt;FIRST. and LAST. variables are automatic variables created for every variable in the BY statement. They will not be included in resulting datasets.&lt;/P&gt;
&lt;P&gt;They are Boolean variables and can only have the values 0 (false) or 1 (true).&lt;/P&gt;
&lt;P&gt;The first IF is a "normal" IF with a THEN branch which will be executed depending on the result of the condition.&lt;/P&gt;
&lt;P&gt;The second IF is a&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p1cxl8ifdt8u0gn12wqbji8o5fq1.htm" target="_blank" rel="noopener"&gt;subsetting IF&lt;/A&gt;. If the condition results in false, the rest of the data step statements are skipped and the next data step iteration starts; no implicit output is performed.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Nov 2022 21:35:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-questions/m-p/842787#M333252</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-11-06T21:35:49Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN questions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-questions/m-p/842788#M333253</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/431484"&gt;@Nietzsche&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi I am currently on page 133 of the official Specialist Prep Guide.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Two things I wish to confirm with the community because book does not explain it regarding to IF/THEN (maybe in later chapters).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First:&amp;nbsp; is IF first.dept the same thing as if first.dept=1 or if first.dept=TRUE? SAS assumes that user mean true (like in python)?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes.&amp;nbsp; Do you know WHY ?&amp;nbsp; &amp;nbsp;Do you know what result SAS returns from the evaluation of a boolean expression (such as first.dept=1) ?&amp;nbsp; &amp;nbsp;Do you know what truth value SAS uses when given a number like 1 to interpret as a boolean?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hint remember that SAS has only two types of variables.&amp;nbsp; Fixed length character strings and floating point numbers.&lt;/P&gt;
&lt;LI-SPOILER&gt;The result of a boolean expression is either 1 (true) or 0 (false).&lt;BR /&gt;&lt;BR /&gt;Zero or missing is considered FALSE.&amp;nbsp; Any other value is considered TRUE.&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Secondly: if nothing is stated after the IF statement like IF last.dept; it just means end everything the IF statement?&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Sort of.&amp;nbsp; They are actually two different statements.&amp;nbsp; Without the THEN you have a &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p1cxl8ifdt8u0gn12wqbji8o5fq1.htm" target="_self"&gt;SUBSETTING IF&lt;/A&gt;&amp;nbsp;statement instead.&amp;nbsp; Basically if the condition is not true this particular iteration of the data step stops immediately.&amp;nbsp; So statements after that are not executed. Note this includes any implied OUTPUT statement that might be executed when the iteration reaches the end of the data step code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Nov 2022 21:40:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-questions/m-p/842788#M333253</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-06T21:40:20Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN questions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-questions/m-p/842791#M333254</link>
      <description>&lt;P&gt;As&amp;nbsp; mentioned in your post the data set company.usa is being sorted using the by variable dept&amp;nbsp; and the sorted values are in work. temp.&lt;BR /&gt;This means all rows having the same value of the variable dept are contiguous.&lt;BR /&gt;For clarity consider that the rows for the variable dept="HR" are being processed in the data step.&lt;BR /&gt;&lt;STRONG&gt;First question :&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;First:&amp;nbsp; is IF first.dept the same thing as if first.dept=1 or if first.dept=TRUE? SAS assumes that user mean true&amp;nbsp;.&lt;BR /&gt;&lt;/SPAN&gt;This statement essentially answers the question : Is this the first value of the department HR?&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Second Question :&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;if nothing is stated after the IF statement like &lt;STRONG&gt;IF last.dept&lt;/STRONG&gt;; it just means end everything the IF statement?&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;This answers the question : Is the value of the variable&amp;nbsp; dept is the last value for dept="HR" ?&lt;BR /&gt;If it is indeed the last value then last,dept becomes true.&lt;BR /&gt;In this question the values of payroll is being calculated for each department. So when the last value of variable dept is reached (&lt;STRONG&gt;last,dept is true&lt;/STRONG&gt;)&amp;nbsp; then the observation or result&amp;nbsp; is output to the dataset budget.&amp;nbsp;&lt;BR /&gt;Thus if the source dataset work.temp has two dept's.&amp;nbsp; then the output budget will have two rows.|&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Nov 2022 21:57:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-questions/m-p/842791#M333254</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2022-11-06T21:57:14Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN questions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-questions/m-p/842982#M333318</link>
      <description>&lt;P&gt;so let me get this straight.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The intention of that subsetting statement without anything code if the IF statement is simply to control the execution (ie, writing to output) only if the subsetting IF is TRUE?&lt;/P&gt;</description>
      <pubDate>Mon, 07 Nov 2022 21:13:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-questions/m-p/842982#M333318</guid>
      <dc:creator>Nietzsche</dc:creator>
      <dc:date>2022-11-07T21:13:38Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN questions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-questions/m-p/842986#M333319</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/431484"&gt;@Nietzsche&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;so let me get this straight.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The intention of that subsetting statement without anything code if the IF statement is simply to control the execution (ie, writing to output) only if the subsetting IF is TRUE?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is an oversimplification, but in a simple data step you can think of that way.&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data males;
  set sashelp.class ;
  if sex='M';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So that type of usage is what led to the SUBSETTING IF name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Play around and see how it works.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example run this data step and check the log.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data males;
   set sashelp.class;
   put  'Before the IF' _n_ = sex= ;
   if sex='M';
   put 'After the IF' _n_= sex= ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;1419  data males;
1420     set sashelp.class;
1421     put  'Before the IF' _n_ = sex= ;
1422     if sex='M';
1423     put 'After the IF' _n_= sex= ;
1424  run;

Before the IF_N_=1 Sex=M
After the IF_N_=1 Sex=M
Before the IF_N_=2 Sex=F
Before the IF_N_=3 Sex=F
Before the IF_N_=4 Sex=F
Before the IF_N_=5 Sex=M
After the IF_N_=5 Sex=M
Before the IF_N_=6 Sex=M
After the IF_N_=6 Sex=M
Before the IF_N_=7 Sex=F
Before the IF_N_=8 Sex=F
Before the IF_N_=9 Sex=M
After the IF_N_=9 Sex=M
Before the IF_N_=10 Sex=M
After the IF_N_=10 Sex=M
Before the IF_N_=11 Sex=F
Before the IF_N_=12 Sex=F
Before the IF_N_=13 Sex=F
Before the IF_N_=14 Sex=F
Before the IF_N_=15 Sex=M
After the IF_N_=15 Sex=M
Before the IF_N_=16 Sex=M
After the IF_N_=16 Sex=M
Before the IF_N_=17 Sex=M
After the IF_N_=17 Sex=M
Before the IF_N_=18 Sex=M
After the IF_N_=18 Sex=M
Before the IF_N_=19 Sex=M
After the IF_N_=19 Sex=M
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.MALES has 10 observations and 5 variables.
&lt;/PRE&gt;
&lt;P&gt;So you can see the second PUT statement only runs on observations where SEX was equal to 'M'.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Nov 2022 21:24:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-questions/m-p/842986#M333319</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-07T21:24:35Z</dc:date>
    </item>
  </channel>
</rss>

