<?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 statement in data step in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/if-statement-in-data-step/m-p/770605#M30903</link>
    <description>&lt;P&gt;Do you want something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data plot1;
   x = today();
   if not (missing(&amp;amp;group1) and missing(&amp;amp;group2)) then y = &amp;amp;totalpopulation/sum(&amp;amp;group1,&amp;amp;group2)); 
   else y=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that's not it, then I really don't understand the problem and I would ask you to discuss the problem (not the code) in more detail. DO NOT ANSWER BY DISCUSSING SAS CODE, ANSWER BY EXPLAINING THE PROBLEM.&lt;/P&gt;</description>
    <pubDate>Mon, 27 Sep 2021 12:02:51 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-09-27T12:02:51Z</dc:date>
    <item>
      <title>if statement in data step</title>
      <link>https://communities.sas.com/t5/New-SAS-User/if-statement-in-data-step/m-p/770599#M30902</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a lot of code but in this specific part where I make a calculation for y for a plot:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;**plot for day 1;
data plot1;
   x = today();
   *y = &amp;amp;totalpopulation/(&amp;amp;group1+&amp;amp;group2); 
   y=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As you can see i commented the line out for the calculation, as most of the time the calculation &lt;CODE class=" language-sas"&gt;(&amp;amp;group1+&amp;amp;group2)&lt;/CODE&gt;&amp;nbsp;will be "." (missing) because of no data in the group. The plot should then be 100%, hence the other y=1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is very manual work for me. Beacuse i need to check if the&amp;nbsp;&lt;CODE class=" language-sas"&gt;(&amp;amp;group1+&amp;amp;group2)&lt;/CODE&gt;&amp;nbsp;will be missing then I should use the other y otherwise the plot will be empty- and I will like to know if there is a if statement you can do here? if &lt;CODE class=" language-sas"&gt;(&amp;amp;group1+&amp;amp;group2)&lt;/CODE&gt;&amp;nbsp; is&amp;nbsp; "." then put y=1&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Sep 2021 11:36:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/if-statement-in-data-step/m-p/770599#M30902</guid>
      <dc:creator>mmea</dc:creator>
      <dc:date>2021-09-27T11:36:13Z</dc:date>
    </item>
    <item>
      <title>Re: if statement in data step</title>
      <link>https://communities.sas.com/t5/New-SAS-User/if-statement-in-data-step/m-p/770605#M30903</link>
      <description>&lt;P&gt;Do you want something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data plot1;
   x = today();
   if not (missing(&amp;amp;group1) and missing(&amp;amp;group2)) then y = &amp;amp;totalpopulation/sum(&amp;amp;group1,&amp;amp;group2)); 
   else y=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that's not it, then I really don't understand the problem and I would ask you to discuss the problem (not the code) in more detail. DO NOT ANSWER BY DISCUSSING SAS CODE, ANSWER BY EXPLAINING THE PROBLEM.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Sep 2021 12:02:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/if-statement-in-data-step/m-p/770605#M30903</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-27T12:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: if statement in data step</title>
      <link>https://communities.sas.com/t5/New-SAS-User/if-statement-in-data-step/m-p/770613#M30905</link>
      <description>&lt;P&gt;Stop adding things like &amp;amp;group1 + &amp;amp;group2. You should use sum function instead because the sum function ignores missing values. You should just use a do block with the missing function to evaluate only among non-missing values of group 1 and group 2 like this:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data plot1;
x=today( ) ;
if ^missing(&amp;amp;group1) and ^missing(&amp;amp;group2) then do;
y=&amp;amp;totalpopulation/sum(&amp;amp;group1,&amp;amp;group2);
end;
else do;
y=1;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Sep 2021 12:38:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/if-statement-in-data-step/m-p/770613#M30905</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-09-27T12:38:18Z</dc:date>
    </item>
  </channel>
</rss>

