<?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 else if +do and missing value generated questions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/else-if-do-and-missing-value-generated-questions/m-p/767958#M243527</link>
    <description>&lt;P&gt;I hope you can see the log output. Ok. Two questions.&lt;/P&gt;&lt;P&gt;(1)&amp;nbsp; The log output sas that missing values were generated on line 1187. If you go the bottom of&amp;nbsp; the posted code you will see 1187 pulled out by itself and the column locations are marked by |&amp;amp;| following the noted column. So i know that there was one record with a missing value for A2WEIGHT and so '.' should have been the result for vbacwk{i}, i=1 to 7 and it was. My question is why was three missing value notes reported. I've seen these messages but i've nerver understood them except for the fact that a missing value was assigned to the result variable for some record in the dataset. Please help me understand.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(2) Now look at lines 1186, 87, and 88. My intention was that if the else if statement is true,&amp;nbsp; both 1187 and 1188 are executed. However, if the else if is false, both 1187 and 1188 are not executed.&lt;/P&gt;&lt;P&gt;These lines execute correctly, as near as i can tell, but why shouldn't i have had to write this instead&lt;/P&gt;&lt;P&gt;1186&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if (valcwk{i} ge 1 and valhwk{i} ge 1) then &lt;STRONG&gt;do&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1187&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vbacwk{i}=((valcwk{i}/2)*(9.0/A2WEIGHT))-(0.02*valhwk{i});&lt;/P&gt;&lt;P&gt;1188&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (vbacwk{i} le 0.0 and vbacwk{i} gt -1.) then vbacwk{i}=0.0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;When i tried that i got this&lt;/P&gt;&lt;P&gt;2335 vbacwk{i}=((valcwk{i}/2)*(9.0/A2WEIGHT))-(0.02*valhwk{i});&lt;BR /&gt;-&lt;BR /&gt;73&lt;BR /&gt;76&lt;BR /&gt;ERROR 73-322: Expecting an =.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why isn't a do required? I want conditionally execute both 1187 and 1188. Why the error?&lt;/P&gt;&lt;P&gt;Thanks, Gene Maguin&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;1173  *   COMPUTE WOMEN'S DAILY BAC BASED ON TYPICAL DAILY DRINKS AND WEIGHT;

1174  *   NOT SURE OF THE EXACT SOURCE BUT SOMEBODY WIDMARK IS NAMED;

1175  *   [(c/2)*(GC/w)] -(B60*t), where c = total standard drinks consumed,

1176      GC = gender constant (9.0 for women, 7.5 for men), w = weight in pounds,

1177      B60 = hourly rate of metabolism of alcohol (estimated at .02), and

1178      t = total drinking hours;

1179  *   PER CRAIG (ABOUT 08.26.2021) COMPUTE BAC AS .p IF DRINKS &amp;gt; 1 AND HOURS=0

1180  *   OR IF DRINKS = 0  AND HOURS &amp;gt; 1;

1181  *   RECODE TO .s IF BAC LE 0.0;

&amp;gt;&amp;gt;&amp;gt;&amp;gt;   array valcwk{i} defined above this section.

1182      array valhwk{7} A2ALCH1-A2ALCH7;

1183      array vbacwk{7} A2BAC1-A2BAC7;

1184      do i=1 to 7;

1185      if (valcwk{i} eq 0 and valhwk{i} eq 0) then vbacwk{i}=.s;

1186      else if (valcwk{i} ge 1 and valhwk{i} ge 1) then

1187         vbacwk{i}=((valcwk{i}/2)*(9.0/A2WEIGHT))-(0.02*valhwk{i});

1188         if (vbacwk{i} le 0.0 and vbacwk{i} gt -1.) then vbacwk{i}=0.0;

1189      else if (valcwk{i} eq .p or valhwk{i} eq .p) then vbacwk{i}=.p;

1190      else if (valcwk{i} eq 0 and valhwk{i} gt 0) then vbacwk{i}=.p;

1191      else if (valcwk{i} gt 0 and valhwk{i} eq 0) then vbacwk{i}=.p;

1192      end;

1193      run;


NOTE: Missing values were generated as a result of performing an operation on missing values.

      Each place is given by: (Number of times) at (Line):(Column).

      1 at 1187:32   1 at 1187:37   1 at 1187:48


1187         vbacwk{i}=((valcwk{i}/2)|&amp;amp;|*(9.0|&amp;amp;|/A2WEIGHT))|&amp;amp;|-(0.02*valhwk{i});

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 15 Sep 2021 18:10:52 GMT</pubDate>
    <dc:creator>emaguin</dc:creator>
    <dc:date>2021-09-15T18:10:52Z</dc:date>
    <item>
      <title>else if +do and missing value generated questions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/else-if-do-and-missing-value-generated-questions/m-p/767958#M243527</link>
      <description>&lt;P&gt;I hope you can see the log output. Ok. Two questions.&lt;/P&gt;&lt;P&gt;(1)&amp;nbsp; The log output sas that missing values were generated on line 1187. If you go the bottom of&amp;nbsp; the posted code you will see 1187 pulled out by itself and the column locations are marked by |&amp;amp;| following the noted column. So i know that there was one record with a missing value for A2WEIGHT and so '.' should have been the result for vbacwk{i}, i=1 to 7 and it was. My question is why was three missing value notes reported. I've seen these messages but i've nerver understood them except for the fact that a missing value was assigned to the result variable for some record in the dataset. Please help me understand.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(2) Now look at lines 1186, 87, and 88. My intention was that if the else if statement is true,&amp;nbsp; both 1187 and 1188 are executed. However, if the else if is false, both 1187 and 1188 are not executed.&lt;/P&gt;&lt;P&gt;These lines execute correctly, as near as i can tell, but why shouldn't i have had to write this instead&lt;/P&gt;&lt;P&gt;1186&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if (valcwk{i} ge 1 and valhwk{i} ge 1) then &lt;STRONG&gt;do&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1187&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vbacwk{i}=((valcwk{i}/2)*(9.0/A2WEIGHT))-(0.02*valhwk{i});&lt;/P&gt;&lt;P&gt;1188&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (vbacwk{i} le 0.0 and vbacwk{i} gt -1.) then vbacwk{i}=0.0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;When i tried that i got this&lt;/P&gt;&lt;P&gt;2335 vbacwk{i}=((valcwk{i}/2)*(9.0/A2WEIGHT))-(0.02*valhwk{i});&lt;BR /&gt;-&lt;BR /&gt;73&lt;BR /&gt;76&lt;BR /&gt;ERROR 73-322: Expecting an =.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why isn't a do required? I want conditionally execute both 1187 and 1188. Why the error?&lt;/P&gt;&lt;P&gt;Thanks, Gene Maguin&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;1173  *   COMPUTE WOMEN'S DAILY BAC BASED ON TYPICAL DAILY DRINKS AND WEIGHT;

1174  *   NOT SURE OF THE EXACT SOURCE BUT SOMEBODY WIDMARK IS NAMED;

1175  *   [(c/2)*(GC/w)] -(B60*t), where c = total standard drinks consumed,

1176      GC = gender constant (9.0 for women, 7.5 for men), w = weight in pounds,

1177      B60 = hourly rate of metabolism of alcohol (estimated at .02), and

1178      t = total drinking hours;

1179  *   PER CRAIG (ABOUT 08.26.2021) COMPUTE BAC AS .p IF DRINKS &amp;gt; 1 AND HOURS=0

1180  *   OR IF DRINKS = 0  AND HOURS &amp;gt; 1;

1181  *   RECODE TO .s IF BAC LE 0.0;

&amp;gt;&amp;gt;&amp;gt;&amp;gt;   array valcwk{i} defined above this section.

1182      array valhwk{7} A2ALCH1-A2ALCH7;

1183      array vbacwk{7} A2BAC1-A2BAC7;

1184      do i=1 to 7;

1185      if (valcwk{i} eq 0 and valhwk{i} eq 0) then vbacwk{i}=.s;

1186      else if (valcwk{i} ge 1 and valhwk{i} ge 1) then

1187         vbacwk{i}=((valcwk{i}/2)*(9.0/A2WEIGHT))-(0.02*valhwk{i});

1188         if (vbacwk{i} le 0.0 and vbacwk{i} gt -1.) then vbacwk{i}=0.0;

1189      else if (valcwk{i} eq .p or valhwk{i} eq .p) then vbacwk{i}=.p;

1190      else if (valcwk{i} eq 0 and valhwk{i} gt 0) then vbacwk{i}=.p;

1191      else if (valcwk{i} gt 0 and valhwk{i} eq 0) then vbacwk{i}=.p;

1192      end;

1193      run;


NOTE: Missing values were generated as a result of performing an operation on missing values.

      Each place is given by: (Number of times) at (Line):(Column).

      1 at 1187:32   1 at 1187:37   1 at 1187:48


1187         vbacwk{i}=((valcwk{i}/2)|&amp;amp;|*(9.0|&amp;amp;|/A2WEIGHT))|&amp;amp;|-(0.02*valhwk{i});

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Sep 2021 18:10:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/else-if-do-and-missing-value-generated-questions/m-p/767958#M243527</guid>
      <dc:creator>emaguin</dc:creator>
      <dc:date>2021-09-15T18:10:52Z</dc:date>
    </item>
    <item>
      <title>Re: else if +do and missing value generated questions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/else-if-do-and-missing-value-generated-questions/m-p/767961#M243528</link>
      <description>&lt;P&gt;if you want multiple lines of code executed after the do, it requires a semicolon.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;If .. then do;
Code to execute….
End;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Otherwise, it only does what comes after the do. It simplifies things if you only have one action.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/273054"&gt;@emaguin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I hope you can see the log output. Ok. Two questions.&lt;/P&gt;
&lt;P&gt;(1)&amp;nbsp; The log output sas that missing values were generated on line 1187. If you go the bottom of&amp;nbsp; the posted code you will see 1187 pulled out by itself and the column locations are marked by |&amp;amp;| following the noted column. So i know that there was one record with a missing value for A2WEIGHT and so '.' should have been the result for vbacwk{i}, i=1 to 7 and it was. My question is why was three missing value notes reported. I've seen these messages but i've nerver understood them except for the fact that a missing value was assigned to the result variable for some record in the dataset. Please help me understand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(2) Now look at lines 1186, 87, and 88. My intention was that if the else if statement is true,&amp;nbsp; both 1187 and 1188 are executed. However, if the else if is false, both 1187 and 1188 are not executed.&lt;/P&gt;
&lt;P&gt;These lines execute correctly, as near as i can tell, but why shouldn't i have had to write this instead&lt;/P&gt;
&lt;P&gt;1186&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if (valcwk{i} ge 1 and valhwk{i} ge 1) then &lt;STRONG&gt;do&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;1187&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vbacwk{i}=((valcwk{i}/2)*(9.0/A2WEIGHT))-(0.02*valhwk{i});&lt;/P&gt;
&lt;P&gt;1188&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (vbacwk{i} le 0.0 and vbacwk{i} gt -1.) then vbacwk{i}=0.0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;end;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;When i tried that i got this&lt;/P&gt;
&lt;P&gt;2335 vbacwk{i}=((valcwk{i}/2)*(9.0/A2WEIGHT))-(0.02*valhwk{i});&lt;BR /&gt;-&lt;BR /&gt;73&lt;BR /&gt;76&lt;BR /&gt;ERROR 73-322: Expecting an =.&lt;/P&gt;
&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why isn't a do required? I want conditionally execute both 1187 and 1188. Why the error?&lt;/P&gt;
&lt;P&gt;Thanks, Gene Maguin&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;1173  *   COMPUTE WOMEN'S DAILY BAC BASED ON TYPICAL DAILY DRINKS AND WEIGHT;

1174  *   NOT SURE OF THE EXACT SOURCE BUT SOMEBODY WIDMARK IS NAMED;

1175  *   [(c/2)*(GC/w)] -(B60*t), where c = total standard drinks consumed,

1176      GC = gender constant (9.0 for women, 7.5 for men), w = weight in pounds,

1177      B60 = hourly rate of metabolism of alcohol (estimated at .02), and

1178      t = total drinking hours;

1179  *   PER CRAIG (ABOUT 08.26.2021) COMPUTE BAC AS .p IF DRINKS &amp;gt; 1 AND HOURS=0

1180  *   OR IF DRINKS = 0  AND HOURS &amp;gt; 1;

1181  *   RECODE TO .s IF BAC LE 0.0;

&amp;gt;&amp;gt;&amp;gt;&amp;gt;   array valcwk{i} defined above this section.

1182      array valhwk{7} A2ALCH1-A2ALCH7;

1183      array vbacwk{7} A2BAC1-A2BAC7;

1184      do i=1 to 7;

1185      if (valcwk{i} eq 0 and valhwk{i} eq 0) then vbacwk{i}=.s;

1186      else if (valcwk{i} ge 1 and valhwk{i} ge 1) then

1187         vbacwk{i}=((valcwk{i}/2)*(9.0/A2WEIGHT))-(0.02*valhwk{i});

1188         if (vbacwk{i} le 0.0 and vbacwk{i} gt -1.) then vbacwk{i}=0.0;

1189      else if (valcwk{i} eq .p or valhwk{i} eq .p) then vbacwk{i}=.p;

1190      else if (valcwk{i} eq 0 and valhwk{i} gt 0) then vbacwk{i}=.p;

1191      else if (valcwk{i} gt 0 and valhwk{i} eq 0) then vbacwk{i}=.p;

1192      end;

1193      run;


NOTE: Missing values were generated as a result of performing an operation on missing values.

      Each place is given by: (Number of times) at (Line):(Column).

      1 at 1187:32   1 at 1187:37   1 at 1187:48


1187         vbacwk{i}=((valcwk{i}/2)|&amp;amp;|*(9.0|&amp;amp;|/A2WEIGHT))|&amp;amp;|-(0.02*valhwk{i});

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Sep 2021 18:16:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/else-if-do-and-missing-value-generated-questions/m-p/767961#M243528</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-09-15T18:16:48Z</dc:date>
    </item>
    <item>
      <title>Re: else if +do and missing value generated questions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/else-if-do-and-missing-value-generated-questions/m-p/767962#M243529</link>
      <description>&lt;P&gt;DO is required, as is a semi-colon after DO (which you don't have)&lt;/P&gt;</description>
      <pubDate>Wed, 15 Sep 2021 18:18:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/else-if-do-and-missing-value-generated-questions/m-p/767962#M243529</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-15T18:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: else if +do and missing value generated questions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/else-if-do-and-missing-value-generated-questions/m-p/768005#M243552</link>
      <description>&lt;P&gt;SAS has many different flavors of DO statements.&lt;/P&gt;
&lt;P&gt;Looks like you intended to run a the bare DO statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if x then do;
  statement1;
  statement2;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But because of the missing semi-colon after the DO instead you ran a version of aniteration DO statement, which can have many forms:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i=1 to 10;
do i=1,3,4,5;
do i=1,5 to 10,13 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But instead of multiple values you only had one value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;SPAN&gt;if (valcwk{i} ge 1 and valhwk{i} ge 1) then&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;do &lt;/STRONG&gt;vbacwk{i}=((valcwk{i}/2)*(9.0/A2WEIGHT))-(0.02*valhwk{i});&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In your code the iteration variable is a reference to an array,&amp;nbsp; vbacwk{i},&amp;nbsp; and SAS syntax does not allow that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is clearer example that demonstrates the coding error:&lt;/P&gt;
&lt;PRE&gt;81    data _null_;
82     set sashelp.class;
83     array n _numeric_;
84     do n[1]= 5-6 ;
           -
           73
           76
ERROR 73-322: Expecting an =.

ERROR 76-322: Syntax error, statement will be ignored.

85       put n[1]=;
86     end;
87    run;

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Sep 2021 01:30:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/else-if-do-and-missing-value-generated-questions/m-p/768005#M243552</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-16T01:30:12Z</dc:date>
    </item>
  </channel>
</rss>

