<?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: Counting Records By Group - if first/last / how to get valid counts in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counting-Records-By-Group-if-first-last-how-to-get-valid-counts/m-p/807684#M318469</link>
    <description>&lt;P&gt;The code on the if first. is almost certainly wrong unless you want to do a logical comparison between one value and the results of two other logical comparisons.&lt;/P&gt;
&lt;P&gt;When you do something like this (and you can copy this as it is text and run in your session)&lt;/P&gt;
&lt;PRE&gt;data example;
   x=3;
   if x=3 then var1=10 and var2=0 and var3=0;
run;&lt;/PRE&gt;
&lt;P&gt;What SAS does when it encounters Var1 = it assumes that EVERYTHING after the = is involved with assigning the value to Var1. This gets coupled with SAS returning 1/0 for true/false from comparisons. So VAR2 is compared to 0,. returning either a 1 or 0. In this case since I do not have a value for VAR2 missing is compared to 0 and returns "not equal" or false, 0. Same for Var3. Var1 = (the result of comparing) 10 and 0 and 0. SAS treats any numeric value other than Missing or 0 as False. So that resolves to Var1 = True and False and False, which is False (true only if all are true) and hence 0.&lt;/P&gt;
&lt;P&gt;To assign non-missing values to multiple variables you need each assignment as a single statement. Like this:&lt;/P&gt;
&lt;PRE&gt;data example;
   x=3;
   if x=3 then do;
     var1=0;
     var2=0; 
     var3=0;
   end;
run;&lt;/PRE&gt;
&lt;P&gt;You might be asking why did I use Var1=10? With your code you may have thought that the Likely_ct=0 was correctly assigned and trying to figure out why the rest weren't. In fact, the result of zero for that was the result of a logical comparison.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So your counts EXCEPT Likely_ct were not resetting at First.Screen.&lt;/P&gt;</description>
    <pubDate>Wed, 13 Apr 2022 21:54:04 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-04-13T21:54:04Z</dc:date>
    <item>
      <title>Counting Records By Group - if first/last / how to get valid counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-Records-By-Group-if-first-last-how-to-get-valid-counts/m-p/807673#M318459</link>
      <description>&lt;P&gt;Can anyone help me identify the problem in code below? I think it might be the first set of if statements creating _ct (count) variables. Those values are very off though in general the code runs and even the final indicators will likely be correct once I can get appropriate values for the _ct variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your suggestions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Clo13_0-1649882178732.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70369iE1EFE9316B427F6E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Clo13_0-1649882178732.png" alt="Clo13_0-1649882178732.png" /&gt;&lt;/span&gt;&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="Clo13_1-1649882272990.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70370i901C8A936795D9D7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Clo13_1-1649882272990.png" alt="Clo13_1-1649882272990.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2022 20:46:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-Records-By-Group-if-first-last-how-to-get-valid-counts/m-p/807673#M318459</guid>
      <dc:creator>Clo13</dc:creator>
      <dc:date>2022-04-13T20:46:24Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Records By Group - if first/last / how to get valid counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-Records-By-Group-if-first-last-how-to-get-valid-counts/m-p/807678#M318464</link>
      <description>&lt;P&gt;Explain the desired output.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;And: show us the desired output for a small example data set (and show us the small example data set as well).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please provide code as text, not as screen captures, pasted into the window that appears when you click on the "little running man" icon.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2022 21:14:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-Records-By-Group-if-first-last-how-to-get-valid-counts/m-p/807678#M318464</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-13T21:14:08Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Records By Group - if first/last / how to get valid counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-Records-By-Group-if-first-last-how-to-get-valid-counts/m-p/807683#M318468</link>
      <description>&lt;P&gt;The issue seems to be how you initialize the _ct vars. Try this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;if first.scrssn then do;
    likely_ct = 0;
    high_likely_ct = 0;
    acute_ct = 0;
end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2022 21:32:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-Records-By-Group-if-first-last-how-to-get-valid-counts/m-p/807683#M318468</guid>
      <dc:creator>average_joe</dc:creator>
      <dc:date>2022-04-13T21:32:22Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Records By Group - if first/last / how to get valid counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-Records-By-Group-if-first-last-how-to-get-valid-counts/m-p/807684#M318469</link>
      <description>&lt;P&gt;The code on the if first. is almost certainly wrong unless you want to do a logical comparison between one value and the results of two other logical comparisons.&lt;/P&gt;
&lt;P&gt;When you do something like this (and you can copy this as it is text and run in your session)&lt;/P&gt;
&lt;PRE&gt;data example;
   x=3;
   if x=3 then var1=10 and var2=0 and var3=0;
run;&lt;/PRE&gt;
&lt;P&gt;What SAS does when it encounters Var1 = it assumes that EVERYTHING after the = is involved with assigning the value to Var1. This gets coupled with SAS returning 1/0 for true/false from comparisons. So VAR2 is compared to 0,. returning either a 1 or 0. In this case since I do not have a value for VAR2 missing is compared to 0 and returns "not equal" or false, 0. Same for Var3. Var1 = (the result of comparing) 10 and 0 and 0. SAS treats any numeric value other than Missing or 0 as False. So that resolves to Var1 = True and False and False, which is False (true only if all are true) and hence 0.&lt;/P&gt;
&lt;P&gt;To assign non-missing values to multiple variables you need each assignment as a single statement. Like this:&lt;/P&gt;
&lt;PRE&gt;data example;
   x=3;
   if x=3 then do;
     var1=0;
     var2=0; 
     var3=0;
   end;
run;&lt;/PRE&gt;
&lt;P&gt;You might be asking why did I use Var1=10? With your code you may have thought that the Likely_ct=0 was correctly assigned and trying to figure out why the rest weren't. In fact, the result of zero for that was the result of a logical comparison.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So your counts EXCEPT Likely_ct were not resetting at First.Screen.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2022 21:54:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-Records-By-Group-if-first-last-how-to-get-valid-counts/m-p/807684#M318469</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-04-13T21:54:04Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Records By Group - if first/last / how to get valid counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-Records-By-Group-if-first-last-how-to-get-valid-counts/m-p/807685#M318470</link>
      <description>Hi Paige. Agreed. I work on SAS via a remote desktop and I have to get a system down for transferring all the helpful info out of the SAS environment.</description>
      <pubDate>Wed, 13 Apr 2022 21:44:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-Records-By-Group-if-first-last-how-to-get-valid-counts/m-p/807685#M318470</guid>
      <dc:creator>Clo13</dc:creator>
      <dc:date>2022-04-13T21:44:57Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Records By Group - if first/last / how to get valid counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-Records-By-Group-if-first-last-how-to-get-valid-counts/m-p/807686#M318471</link>
      <description>Thank you so much! That works! I need to study more. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Wed, 13 Apr 2022 21:46:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-Records-By-Group-if-first-last-how-to-get-valid-counts/m-p/807686#M318471</guid>
      <dc:creator>Clo13</dc:creator>
      <dc:date>2022-04-13T21:46:24Z</dc:date>
    </item>
  </channel>
</rss>

