<?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 categorical variables using data command in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counting-categorical-variables-using-data-command/m-p/424226#M104459</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/184431"&gt;@exbalterate&lt;/a&gt;&amp;nbsp;Sure, we the community are here to help you and sas users across the world. If it is a new query, i would suggest you to open up a new thread so that you may get various responses and you can pick the best. Also, if you are satisfied with the answer you got here and are not waiting for more responses, kindly mark the question as answered. Thank you&lt;/P&gt;</description>
    <pubDate>Mon, 01 Jan 2018 21:16:31 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-01-01T21:16:31Z</dc:date>
    <item>
      <title>Counting categorical variables using data command</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-categorical-variables-using-data-command/m-p/424173#M104421</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was wondering if it is possible to use &lt;STRONG&gt;data&lt;/STRONG&gt; instead of &lt;STRONG&gt;proc&lt;/STRONG&gt; to count the number of categorical variables on a row as shown in 'count' example below. This will allow me to further use the data e.g COUNT=1 or COUNT &amp;gt; 1 to check morbidity.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also will it be possible to then count the number of each diagnosis in the entire data set per patient while accounting for duplicates if there is any? For example there are 3 CB's and 2 AA's in this data set but CB should be 2 because Patient 2 had it recorded twice.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your time and have a lovely new year.&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="Untitledsas.png" style="width: 385px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17570i22CD7961B92C6430/image-size/large?v=v2&amp;amp;px=999" role="button" title="Untitledsas.png" alt="Untitledsas.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 31 Dec 2017 18:41:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-categorical-variables-using-data-command/m-p/424173#M104421</guid>
      <dc:creator>exbalterate</dc:creator>
      <dc:date>2017-12-31T18:41:54Z</dc:date>
    </item>
    <item>
      <title>Re: Counting categorical variables using data command</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-categorical-variables-using-data-command/m-p/424174#M104422</link>
      <description>&lt;P&gt;You could do something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data want;&lt;/P&gt;&lt;P&gt;set your_inputdataset;&lt;/P&gt;&lt;P&gt;array g(*)&amp;nbsp; diag1-diag4;&lt;/P&gt;&lt;P&gt;count=dim(g)-cmiss(of g(*));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 31 Dec 2017 18:50:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-categorical-variables-using-data-command/m-p/424174#M104422</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-12-31T18:50:07Z</dc:date>
    </item>
    <item>
      <title>Re: Counting categorical variables using data command</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-categorical-variables-using-data-command/m-p/424176#M104424</link>
      <description>&lt;P&gt;you could use the nmiss function: 4 - nmiss(of, diag1-diag4)?&lt;/P&gt;</description>
      <pubDate>Sun, 31 Dec 2017 18:54:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-categorical-variables-using-data-command/m-p/424176#M104424</guid>
      <dc:creator>pau13rown</dc:creator>
      <dc:date>2017-12-31T18:54:47Z</dc:date>
    </item>
    <item>
      <title>Re: Counting categorical variables using data command</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-categorical-variables-using-data-command/m-p/424178#M104426</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/183379"&gt;@pau13rown&lt;/a&gt;&amp;nbsp;Sir, Since OP's example has char values for the variable Diag1-4, I'm afraid NMISS function will unnecessarily warrant a note&amp;nbsp;: Character values have been converted to numeric values at the places given by: (Line):(Column).&lt;BR /&gt;125:10 125:12&lt;/P&gt;&lt;P&gt;Cmiss handles both char and numeric values. Also using dim(array) makes it dynamic as opposed to using constant 4. Just my 2 cents&lt;/P&gt;</description>
      <pubDate>Sun, 31 Dec 2017 19:46:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-categorical-variables-using-data-command/m-p/424178#M104426</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-12-31T19:46:08Z</dc:date>
    </item>
    <item>
      <title>Re: Counting categorical variables using data command</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-categorical-variables-using-data-command/m-p/424225#M104458</link>
      <description>&lt;P&gt;Thank you, that worked perfectly. Could you help with the other query? Grouping the same type of diagnosis?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jan 2018 20:57:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-categorical-variables-using-data-command/m-p/424225#M104458</guid>
      <dc:creator>exbalterate</dc:creator>
      <dc:date>2018-01-01T20:57:45Z</dc:date>
    </item>
    <item>
      <title>Re: Counting categorical variables using data command</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-categorical-variables-using-data-command/m-p/424226#M104459</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/184431"&gt;@exbalterate&lt;/a&gt;&amp;nbsp;Sure, we the community are here to help you and sas users across the world. If it is a new query, i would suggest you to open up a new thread so that you may get various responses and you can pick the best. Also, if you are satisfied with the answer you got here and are not waiting for more responses, kindly mark the question as answered. Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jan 2018 21:16:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-categorical-variables-using-data-command/m-p/424226#M104459</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-01T21:16:31Z</dc:date>
    </item>
    <item>
      <title>Re: Counting categorical variables using data command</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-categorical-variables-using-data-command/m-p/424250#M104460</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/184431"&gt;@exbalterate&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;"&lt;EM&gt;Also will it be possible to then count the number of each diagnosis in the entire data set per patient while accounting for duplicates&lt;/EM&gt;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, that's certainly possible but please provide sample data in form of a SAS data step and not as a screenshot. Provide also the desired result. This allows us to post code which is actually tested.&lt;/P&gt;
&lt;P&gt;Please make also sure that your sample data is representative, i.e. if there can be multiple rows for a patient then include such a case in your sample data. If there can't be multiple rows then tell us.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It also always helps if you post some of your code whether already working or not. This makes it much easier for us to understand where you're coming from and also helps us to understand your level of&amp;nbsp;SAS proficiency so that we can better tailor our answers to your current SAS expertise.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jan 2018 04:10:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-categorical-variables-using-data-command/m-p/424250#M104460</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-01-02T04:10:05Z</dc:date>
    </item>
    <item>
      <title>Re: Counting categorical variables using data command</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-categorical-variables-using-data-command/m-p/424370#M104499</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/184431"&gt;@exbalterate&lt;/a&gt;&amp;nbsp;you can do in in the following way also&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;infile cards dlm= '09'x missover;&lt;BR /&gt;input patient diag1$ diag2$ diag3$ diag4$;&lt;BR /&gt;cards;&lt;BR /&gt;1 AA J9 HH6&lt;BR /&gt;2 CB CB&lt;BR /&gt;3 J10 AA CB J10&lt;BR /&gt;4 BB K90&lt;BR /&gt;5 J10&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set test ;&lt;BR /&gt;array a (*) diag1-diag4;&lt;BR /&gt;count = 0;&lt;BR /&gt;do i = 1 to dim(a);&lt;BR /&gt;if a(i) ne " " then count+1;&lt;BR /&gt;end;&lt;BR /&gt;drop i;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jan 2018 16:45:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-categorical-variables-using-data-command/m-p/424370#M104499</guid>
      <dc:creator>soham_sas</dc:creator>
      <dc:date>2018-01-02T16:45:59Z</dc:date>
    </item>
  </channel>
</rss>

