<?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: Sum frequencies across multiple variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Sum-frequencies-across-multiple-variables/m-p/764761#M30505</link>
    <description>&lt;P&gt;Please explain more about what output you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the goal is to summarize each of the multiple diagnosis variables separately then that is simple.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=wide;
  tables diag: ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if you want to create some type of combined summary that ignores the order that diagnosis appears. For example that counts the number of times that "stroke" appears independent of which variable it appears in then you will essentially need to get the data into a single variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could possibly create a bunch of binary variables on each observation and then summarize those, but that is much harder to expand to other diagnoses.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data really_wide;
   set wide ;
   cancer = 0 &amp;lt; whichc('cancer', of diag:);
   stroke = 0 &amp;lt; whichc('stroke ', of diag:);
   ...
run;
proc means sum mean min max  data=really_wide;
  var cancer stroke ....;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;The SUM of a binary variable is number of times it is true. The mean is the percent true. The min is whether it is ever false The max is whether it is ever true.&lt;/P&gt;</description>
    <pubDate>Sun, 29 Aug 2021 20:19:03 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-08-29T20:19:03Z</dc:date>
    <item>
      <title>Sum frequencies across multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-frequencies-across-multiple-variables/m-p/764759#M30504</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to create a new variable in my dataset which counts the frequency of diagnoses per ID. I want the frequency variable to count any diagnosis - except "stress" or missing values. Below is an example of my dataset and desired output.&lt;/P&gt;
&lt;P&gt;Any help would be much appreciated. Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Desired output:&lt;/P&gt;
&lt;TABLE border="1" width="56.250000000000014%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;ID&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;visit_num&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;diag&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;age&lt;/TD&gt;
&lt;TD width="8.333333333333334%" height="30px"&gt;frequency&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;diabetes&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;42&lt;/TD&gt;
&lt;TD width="8.333333333333334%" height="30px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;2&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;stroke&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;78&lt;/TD&gt;
&lt;TD width="8.333333333333334%" height="30px"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;2&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;2&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;stress&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="8.333333333333334%" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="16.666666666666668%"&gt;2&lt;/TD&gt;
&lt;TD width="16.666666666666668%"&gt;3&lt;/TD&gt;
&lt;TD width="16.666666666666668%"&gt;stroke&lt;/TD&gt;
&lt;TD width="16.666666666666668%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="8.333333333333334%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;3&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;infection&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;61&lt;/TD&gt;
&lt;TD width="8.333333333333334%" height="30px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;3&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;2&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="8.333333333333334%" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id visit_num diag$ age;
cards;
01 1 diabetes 42 
02 1 stroke 78 
02 2 stress . 
02 3 stroke . 
03 1 infection 61 
03 2 . . 

;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Sep 2021 12:56:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-frequencies-across-multiple-variables/m-p/764759#M30504</guid>
      <dc:creator>monsterpie</dc:creator>
      <dc:date>2021-09-07T12:56:18Z</dc:date>
    </item>
    <item>
      <title>Re: Sum frequencies across multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-frequencies-across-multiple-variables/m-p/764761#M30505</link>
      <description>&lt;P&gt;Please explain more about what output you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the goal is to summarize each of the multiple diagnosis variables separately then that is simple.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=wide;
  tables diag: ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if you want to create some type of combined summary that ignores the order that diagnosis appears. For example that counts the number of times that "stroke" appears independent of which variable it appears in then you will essentially need to get the data into a single variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could possibly create a bunch of binary variables on each observation and then summarize those, but that is much harder to expand to other diagnoses.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data really_wide;
   set wide ;
   cancer = 0 &amp;lt; whichc('cancer', of diag:);
   stroke = 0 &amp;lt; whichc('stroke ', of diag:);
   ...
run;
proc means sum mean min max  data=really_wide;
  var cancer stroke ....;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;The SUM of a binary variable is number of times it is true. The mean is the percent true. The min is whether it is ever false The max is whether it is ever true.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Aug 2021 20:19:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-frequencies-across-multiple-variables/m-p/764761#M30505</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-29T20:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: Sum frequencies across multiple variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-frequencies-across-multiple-variables/m-p/765392#M30553</link>
      <description>&lt;P&gt;Thanks for your response &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;.&amp;nbsp;I just updated my question to be much more clear about my objectives, which is closer to the latter of what you suggested. However, I am just trying to get one variable that counts the number of diagnoses per ID. Thank you for your help.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 15:18:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-frequencies-across-multiple-variables/m-p/765392#M30553</guid>
      <dc:creator>monsterpie</dc:creator>
      <dc:date>2021-09-01T15:18:08Z</dc:date>
    </item>
  </channel>
</rss>

