<?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: Flag presence/absence across variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Flag-presence-absence-across-variables/m-p/951931#M42792</link>
    <description>&lt;P&gt;Are these binary variables?&amp;nbsp; Do you want the COUNT of how many were true (as the variable name implies) or another binary variable?&lt;/P&gt;
&lt;P&gt;This seems to express what you want.&lt;/P&gt;
&lt;P&gt;First let's make a HAVE dataset that included the expected result.&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID :$20. Admission :date. Discharge :date. Index Variable1-Variable3 expect;
  format Admission Discharge date9.;
cards;
166  16FEB2019 26FEB2019  1   1   0  0  1
166  18MAR2019 25MAR2019  0   0   0  0  0
166  12APR2020 02JUN2020  0   0   0  0  0
170  22FEB2017 07MAR2017  1   0   0  0  0
170  22FEB2017 07MAR2017  0   0   0  0  0
170  30JAN2019 04MAR2019  0   0   0  0  0
313  03MAR2016 10MAR2016  1   0   1  0  1
313  03MAR2016 10MAR2016  0   0   0  0  0
313  12DEC2019 15DEC2019  0   0   0  0  0
215  22DEC2014 25DEC2014  1   1   0  0  1
; 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;Now we can take advantage of the 0/1 coding to use a simple expression to calculate the COUNT of how many are TRUE when INDEX is TRUE&amp;nbsp; like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  count=index*sum(of variable1-variable3);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If instead of a COUNT you actual want another boolean flag then use the MAX() function instead of the SUM() function.&amp;nbsp; Or replace the * operator with the AND operator instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;3162  proc print;
3163    where count ne expect;
3164  run;

NOTE: No observations were selected from data set WORK.WANT.
NOTE: There were 0 observations read from the data set WORK.WANT.
      WHERE count not = expect;
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 26 Nov 2024 15:07:27 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-11-26T15:07:27Z</dc:date>
    <item>
      <title>Flag presence/absence across variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Flag-presence-absence-across-variables/m-p/951918#M42789</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input ID :$20. Admission :date09. Discharge :date09. Index Variable1 Variable2 Variable3;
  format Admission date9. Discharge date9.;
cards;
166  16FEB2019 26FEB2019  1   1   0  0
166  18MAR2019 25MAR2019  0   0   0  0
166  12APR2020 02JUN2020  0   0   0  0
170  22FEB2017 07MAR2017  1   0   0  0
170  22FEB2017 07MAR2017  0   0   0  0
170  30JAN2019 04MAR2019  0   0   0  0
313  03MAR2016 10MAR2016  1   0   1  0
313  03MAR2016 10MAR2016  0   0   0  0
313  12DEC2019 15DEC2019  0   0   0  0
215  22DEC2014 25DEC2014  1   1   0  0  
; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there a way to get the following?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB1;
  input ID :$20. Admission :date09. Discharge :date09. Index Variable1 Variable2 Variable3 Count;
  format Admission date9. Discharge date9.;
cards;
166  16FEB2019 26FEB2019  1   1   0  0  1
166  18MAR2019 25MAR2019  0   0   0  0  0
166  12APR2020 02JUN2020  0   0   0  0  0
170  22FEB2017 07MAR2017  1   0   0  0  0
170  22FEB2017 07MAR2017  0   0   0  0  0
170  30JAN2019 04MAR2019  0   0   0  0  0
313  03MAR2016 10MAR2016  1   0   1  0  1
313  03MAR2016 10MAR2016  0   0   0  0  0
313  12DEC2019 15DEC2019  0   0   0  0  0
215  22DEC2014 25DEC2014  1   1   0  0  1
; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In other words where Index = 1 if there is at least one record = 1 in Variable1-3 then add a new variable Count = 1 otherwise 0.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2024 14:25:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Flag-presence-absence-across-variables/m-p/951918#M42789</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-11-26T14:25:06Z</dc:date>
    </item>
    <item>
      <title>Re: Flag presence/absence across variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Flag-presence-absence-across-variables/m-p/951928#M42791</link>
      <description>&lt;P&gt;Seems as if when INDEX=1, you want to test to see if there is a 1 in variable1-variable3. Testing these three variables is a simple series of IF statements, or better yet you can use the SUM function&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if sum(of variable1-variable3)&amp;gt;0 then ... ;
else ... ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2024 14:52:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Flag-presence-absence-across-variables/m-p/951928#M42791</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-11-26T14:52:18Z</dc:date>
    </item>
    <item>
      <title>Re: Flag presence/absence across variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Flag-presence-absence-across-variables/m-p/951931#M42792</link>
      <description>&lt;P&gt;Are these binary variables?&amp;nbsp; Do you want the COUNT of how many were true (as the variable name implies) or another binary variable?&lt;/P&gt;
&lt;P&gt;This seems to express what you want.&lt;/P&gt;
&lt;P&gt;First let's make a HAVE dataset that included the expected result.&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID :$20. Admission :date. Discharge :date. Index Variable1-Variable3 expect;
  format Admission Discharge date9.;
cards;
166  16FEB2019 26FEB2019  1   1   0  0  1
166  18MAR2019 25MAR2019  0   0   0  0  0
166  12APR2020 02JUN2020  0   0   0  0  0
170  22FEB2017 07MAR2017  1   0   0  0  0
170  22FEB2017 07MAR2017  0   0   0  0  0
170  30JAN2019 04MAR2019  0   0   0  0  0
313  03MAR2016 10MAR2016  1   0   1  0  1
313  03MAR2016 10MAR2016  0   0   0  0  0
313  12DEC2019 15DEC2019  0   0   0  0  0
215  22DEC2014 25DEC2014  1   1   0  0  1
; 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;Now we can take advantage of the 0/1 coding to use a simple expression to calculate the COUNT of how many are TRUE when INDEX is TRUE&amp;nbsp; like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  count=index*sum(of variable1-variable3);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If instead of a COUNT you actual want another boolean flag then use the MAX() function instead of the SUM() function.&amp;nbsp; Or replace the * operator with the AND operator instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;3162  proc print;
3163    where count ne expect;
3164  run;

NOTE: No observations were selected from data set WORK.WANT.
NOTE: There were 0 observations read from the data set WORK.WANT.
      WHERE count not = expect;
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2024 15:07:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Flag-presence-absence-across-variables/m-p/951931#M42792</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-26T15:07:27Z</dc:date>
    </item>
  </channel>
</rss>

