<?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 If then statement in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/If-then-statement/m-p/619520#M19397</link>
    <description>&lt;P&gt;Using SAS 9.4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have numeric data and I am trying to count across multiple columns to get the total number of columns per row that have a non 0/non missing (.) number.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An example of my data is below. As you can see I can have 0 or . and I do not want to add those to my count. SO for the example below the count would be 8.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;sl_mcpjoints&lt;/TD&gt;&lt;TD&gt;sl_thump_mcp&lt;/TD&gt;&lt;TD&gt;sl_wrist&lt;/TD&gt;&lt;TD&gt;sl_wrist_4cm&lt;/TD&gt;&lt;TD&gt;sl_wrist_8cm&lt;/TD&gt;&lt;TD&gt;sl_wrist_12cm&lt;/TD&gt;&lt;TD&gt;sl_wrist_16cm&lt;/TD&gt;&lt;TD&gt;sl_wrist_20cm&lt;/TD&gt;&lt;TD&gt;sl_wrist_24cm&lt;/TD&gt;&lt;TD&gt;sl_wrist_28cm&lt;/TD&gt;&lt;TD&gt;sl_wrist_32cm&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;18.5&lt;/TD&gt;&lt;TD&gt;18.8&lt;/TD&gt;&lt;TD&gt;15.2&lt;/TD&gt;&lt;TD&gt;14.8&lt;/TD&gt;&lt;TD&gt;16.7&lt;/TD&gt;&lt;TD&gt;20.5&lt;/TD&gt;&lt;TD&gt;22.9&lt;/TD&gt;&lt;TD&gt;24.2&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am running the following code but it is producing a count of 11. Any thoughts on what I am doing incorrectly? Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;set have;&lt;BR /&gt;if sl_MCPjoints &amp;gt;0 then sl_W_count_1 = 1;&lt;BR /&gt;if sl_thump_mcp &amp;gt;0 then sl_W_count_2 = 1;&lt;BR /&gt;if sl_wrist &amp;gt;0 then sl_W_count_3 = 1;&lt;BR /&gt;if sl_wrist_4cm &amp;gt;0 then sl_W_count_4 = 1;&lt;BR /&gt;if sl_wrist_8cm &amp;gt;0 then sl_W_count_5 = 1;&lt;BR /&gt;if sl_wrist_12cm &amp;gt;0 then sl_W_count_6 = 1;&lt;BR /&gt;if sl_wrist_16cm &amp;gt;0 then sl_W_count_7 = 1;&lt;BR /&gt;if sl_wrist_20cm &amp;gt;0 then sl_W_count_8 = 1;&lt;BR /&gt;if sl_wrist_24cm &amp;gt;0 then sl_W_count_9 = 1;&lt;BR /&gt;if sl_wrist_28cm &amp;gt;0 then sl_W_count_10 = 1;&lt;BR /&gt;if sl_wrist_32cm &amp;gt;0 then sl_W_count_11 = 1;&lt;BR /&gt;if sl_elbow_crease &amp;gt;0 then sl_E_count_12 = 1;&lt;BR /&gt;if sl_elbow_4cm &amp;gt;0 then sl_E_count_13 = 1;&lt;BR /&gt;if sl_elbow_8cm &amp;gt;0 then sl_E_count_14 = 1;&lt;BR /&gt;if sl_elbow_12cm &amp;gt;0 then sl_E_count_15 = 1;&lt;BR /&gt;if sl_elbow_16cm &amp;gt;0 then sl_E_count_16 = 1;&lt;BR /&gt;if sl_elbow_20cm &amp;gt;0 then sl_E_count_17 = 1;&lt;BR /&gt;if sl_elbow_24cm &amp;gt;0 then sl_E_count_18 = 1;&lt;BR /&gt;if sl_elbow_28cm &amp;gt;0 then sl_E_count_19 = 1;&lt;BR /&gt;if sl_elbow_32cm &amp;gt;0 then sl_E_count_20 = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PRE_SL_W_count = (sl_W_count_1 + sl_W_count_2 + sl_W_count_3 + sl_W_count_4 + sl_W_count_5 + sl_W_count_6 + sl_W_count_7 + sl_W_count_8 + sl_W_count_9 + sl_W_count_10 + sl_W_count_11);&lt;BR /&gt;PRE_SL_E_count = (sl_E_count_12 + sl_E_count_13 + sl_E_count_14 + sl_E_count_15 + sl_E_count_16 + sl_E_count_17 + sl_E_count_18 + sl_E_count_19 + sl_E_count_20);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Thu, 23 Jan 2020 14:22:14 GMT</pubDate>
    <dc:creator>GS2</dc:creator>
    <dc:date>2020-01-23T14:22:14Z</dc:date>
    <item>
      <title>If then statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/If-then-statement/m-p/619520#M19397</link>
      <description>&lt;P&gt;Using SAS 9.4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have numeric data and I am trying to count across multiple columns to get the total number of columns per row that have a non 0/non missing (.) number.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An example of my data is below. As you can see I can have 0 or . and I do not want to add those to my count. SO for the example below the count would be 8.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;sl_mcpjoints&lt;/TD&gt;&lt;TD&gt;sl_thump_mcp&lt;/TD&gt;&lt;TD&gt;sl_wrist&lt;/TD&gt;&lt;TD&gt;sl_wrist_4cm&lt;/TD&gt;&lt;TD&gt;sl_wrist_8cm&lt;/TD&gt;&lt;TD&gt;sl_wrist_12cm&lt;/TD&gt;&lt;TD&gt;sl_wrist_16cm&lt;/TD&gt;&lt;TD&gt;sl_wrist_20cm&lt;/TD&gt;&lt;TD&gt;sl_wrist_24cm&lt;/TD&gt;&lt;TD&gt;sl_wrist_28cm&lt;/TD&gt;&lt;TD&gt;sl_wrist_32cm&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;18.5&lt;/TD&gt;&lt;TD&gt;18.8&lt;/TD&gt;&lt;TD&gt;15.2&lt;/TD&gt;&lt;TD&gt;14.8&lt;/TD&gt;&lt;TD&gt;16.7&lt;/TD&gt;&lt;TD&gt;20.5&lt;/TD&gt;&lt;TD&gt;22.9&lt;/TD&gt;&lt;TD&gt;24.2&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am running the following code but it is producing a count of 11. Any thoughts on what I am doing incorrectly? Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;set have;&lt;BR /&gt;if sl_MCPjoints &amp;gt;0 then sl_W_count_1 = 1;&lt;BR /&gt;if sl_thump_mcp &amp;gt;0 then sl_W_count_2 = 1;&lt;BR /&gt;if sl_wrist &amp;gt;0 then sl_W_count_3 = 1;&lt;BR /&gt;if sl_wrist_4cm &amp;gt;0 then sl_W_count_4 = 1;&lt;BR /&gt;if sl_wrist_8cm &amp;gt;0 then sl_W_count_5 = 1;&lt;BR /&gt;if sl_wrist_12cm &amp;gt;0 then sl_W_count_6 = 1;&lt;BR /&gt;if sl_wrist_16cm &amp;gt;0 then sl_W_count_7 = 1;&lt;BR /&gt;if sl_wrist_20cm &amp;gt;0 then sl_W_count_8 = 1;&lt;BR /&gt;if sl_wrist_24cm &amp;gt;0 then sl_W_count_9 = 1;&lt;BR /&gt;if sl_wrist_28cm &amp;gt;0 then sl_W_count_10 = 1;&lt;BR /&gt;if sl_wrist_32cm &amp;gt;0 then sl_W_count_11 = 1;&lt;BR /&gt;if sl_elbow_crease &amp;gt;0 then sl_E_count_12 = 1;&lt;BR /&gt;if sl_elbow_4cm &amp;gt;0 then sl_E_count_13 = 1;&lt;BR /&gt;if sl_elbow_8cm &amp;gt;0 then sl_E_count_14 = 1;&lt;BR /&gt;if sl_elbow_12cm &amp;gt;0 then sl_E_count_15 = 1;&lt;BR /&gt;if sl_elbow_16cm &amp;gt;0 then sl_E_count_16 = 1;&lt;BR /&gt;if sl_elbow_20cm &amp;gt;0 then sl_E_count_17 = 1;&lt;BR /&gt;if sl_elbow_24cm &amp;gt;0 then sl_E_count_18 = 1;&lt;BR /&gt;if sl_elbow_28cm &amp;gt;0 then sl_E_count_19 = 1;&lt;BR /&gt;if sl_elbow_32cm &amp;gt;0 then sl_E_count_20 = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PRE_SL_W_count = (sl_W_count_1 + sl_W_count_2 + sl_W_count_3 + sl_W_count_4 + sl_W_count_5 + sl_W_count_6 + sl_W_count_7 + sl_W_count_8 + sl_W_count_9 + sl_W_count_10 + sl_W_count_11);&lt;BR /&gt;PRE_SL_E_count = (sl_E_count_12 + sl_E_count_13 + sl_E_count_14 + sl_E_count_15 + sl_E_count_16 + sl_E_count_17 + sl_E_count_18 + sl_E_count_19 + sl_E_count_20);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2020 14:22:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/If-then-statement/m-p/619520#M19397</guid>
      <dc:creator>GS2</dc:creator>
      <dc:date>2020-01-23T14:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: If then statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/If-then-statement/m-p/619524#M19398</link>
      <description>&lt;P&gt;Use an array:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
set have;
array _nums {*} _numeric_;
PRE_SL_W_count = 0;
do _i = 1 to dim(_nums);
  if nums{_i} not in (0,.) then PRE_SL_W_count = PRE_SL_W_count + 1;
end;
drop _i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have variables that should not be tested, you need to use an explicit variable list in the array statement.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2020 14:30:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/If-then-statement/m-p/619524#M19398</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-23T14:30:52Z</dc:date>
    </item>
    <item>
      <title>Re: If then statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/If-then-statement/m-p/619525#M19399</link>
      <description>&lt;P&gt;When you want to perform the same operations across many columns, use arrays&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
    set have;
    array x sl_wrist--sl_wrist_32cm;
    w_count=0;
    
    do i=1 to dim(x);
        if x(i)&amp;gt;0 then w_count=w_count+1;
    end;
    drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can modify the code to add in e_count.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2020 14:34:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/If-then-statement/m-p/619525#M19399</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-23T14:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: If then statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/If-then-statement/m-p/619527#M19400</link>
      <description>&lt;P&gt;Do you need all of those flag variables also? Or just the count?&lt;/P&gt;
&lt;P&gt;Did you mean you want to count the number of positive values? That is what your code is doing.&amp;nbsp; But your original problem statement was you wanted to count non-zero,non-missing values.&amp;nbsp; Is it possible the value is ever negative?&amp;nbsp; If so is that the same as zero or missing?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because of the need to exclude zero values you will probably want to use an array statement to simplify the coding.&lt;/P&gt;
&lt;P&gt;If you just want to test for not zero and not missing then treat the value as a boolean.&amp;nbsp; SAS evaluates any non-zero value as TRUE and anything else (zero or missing) as FALSE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  set have;
  array si 
sl_MCPjoints   
sl_thump_mcp   
sl_wrist       
sl_wrist_4cm   
sl_wrist_8cm   
sl_wrist_12cm  
sl_wrist_16cm  
sl_wrist_20cm  
sl_wrist_24cm  
sl_wrist_28cm  
sl_wrist_32cm  
sl_elbow_crease
sl_elbow_4cm   
sl_elbow_8cm   
sl_elbow_12cm  
sl_elbow_16cm  
sl_elbow_20cm  
sl_elbow_24cm  
sl_elbow_28cm  
sl_elbow_32cm  
  ;
  PRE_SL_W_count=0;
  do index=1 to dim(SI);
      if si[index] then PRE_SL_W_count = PRE_SL_W_count+1;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Jan 2020 14:35:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/If-then-statement/m-p/619527#M19400</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-23T14:35:29Z</dc:date>
    </item>
  </channel>
</rss>

