<?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 Counting the frequency/count of a numeric constant across a specific set of variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-frequency-count-of-a-numeric-constant-across-a/m-p/517238#M139797</link>
    <description>&lt;P&gt;Hello. I have data in the wide format. There are 5,530 variables for each observation that contain 0, 1, 2, 3, 4, or missing. Those numbers represent a type of location for healthcare services (e.g., 1 = in patient, 2 = emergency department). I am trying to use the COUNT function to get the frequency for each of those values (0-4) for each observation. So far, I am not able to get the correct count.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To note, I did the simpler version of this and DID NOT specify which variables to count within, and I did get the correct number of those values, but that data step included those numbers from the PATID variable, which has 15-20 individual numbers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is an example of the code for the data. Tos_Cd1 is the root variable name. There are 5,530 of these variables, hence the Tos_Cd1&lt;STRONG&gt;1&lt;/STRONG&gt;-Tos_Cd1&lt;STRONG&gt;5530&lt;/STRONG&gt;. Could someone please inform me where I can correct the code? Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data example1;&lt;/P&gt;&lt;P&gt;set example;&lt;/P&gt;&lt;P&gt;array string{*} &lt;SPAN&gt;Tos_Cd11-Tos_Cd15530;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; do i=1 to dim(string);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;HCRU_Other=countc(string(i),'0');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;HCRU_IP=countc(string(i),'1');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;*and so on...;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 29 Nov 2018 20:57:22 GMT</pubDate>
    <dc:creator>dwhitney</dc:creator>
    <dc:date>2018-11-29T20:57:22Z</dc:date>
    <item>
      <title>Counting the frequency/count of a numeric constant across a specific set of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-frequency-count-of-a-numeric-constant-across-a/m-p/517238#M139797</link>
      <description>&lt;P&gt;Hello. I have data in the wide format. There are 5,530 variables for each observation that contain 0, 1, 2, 3, 4, or missing. Those numbers represent a type of location for healthcare services (e.g., 1 = in patient, 2 = emergency department). I am trying to use the COUNT function to get the frequency for each of those values (0-4) for each observation. So far, I am not able to get the correct count.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To note, I did the simpler version of this and DID NOT specify which variables to count within, and I did get the correct number of those values, but that data step included those numbers from the PATID variable, which has 15-20 individual numbers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is an example of the code for the data. Tos_Cd1 is the root variable name. There are 5,530 of these variables, hence the Tos_Cd1&lt;STRONG&gt;1&lt;/STRONG&gt;-Tos_Cd1&lt;STRONG&gt;5530&lt;/STRONG&gt;. Could someone please inform me where I can correct the code? Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data example1;&lt;/P&gt;&lt;P&gt;set example;&lt;/P&gt;&lt;P&gt;array string{*} &lt;SPAN&gt;Tos_Cd11-Tos_Cd15530;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; do i=1 to dim(string);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;HCRU_Other=countc(string(i),'0');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;HCRU_IP=countc(string(i),'1');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;*and so on...;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Nov 2018 20:57:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-frequency-count-of-a-numeric-constant-across-a/m-p/517238#M139797</guid>
      <dc:creator>dwhitney</dc:creator>
      <dc:date>2018-11-29T20:57:22Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the frequency/count of a numeric constant across a specific set of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-frequency-count-of-a-numeric-constant-across-a/m-p/517262#M139805</link>
      <description>&lt;P&gt;See if this helps:&lt;/P&gt;
&lt;PRE&gt;data example1;
   set example;
   array string{*} Tos_Cd11-Tos_Cd15530;
  HCRU_Other=countc(cats(of string(*),'0');
  HCRU_IP=countc(cats(of string(*),'1');;
run;
&lt;/PRE&gt;
&lt;P&gt;This assumes that the 0, 1 or whatever only occurs once per variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above code creates one string value from all of the variables and then counts the characters in the resulting combined string.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Nov 2018 21:19:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-frequency-count-of-a-numeric-constant-across-a/m-p/517262#M139805</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-11-29T21:19:56Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the frequency/count of a numeric constant across a specific set of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-frequency-count-of-a-numeric-constant-across-a/m-p/517276#M139811</link>
      <description>&lt;P&gt;Thanks for the response. Unfortunately, it did not run.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I added another ")" (below), and was getting the following error: ERROR 71-185: The COUNTC function call does not have enough arguments. Any ideas why?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data example1;
   set example;
   array string{*} Tos_Cd11-Tos_Cd15530;&lt;BR /&gt;HCRU_Other=countc(cats(of string(*),'0'));&lt;BR /&gt;HCRU_IP=countc(cats(of string(*),'1'));
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Nov 2018 21:42:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-frequency-count-of-a-numeric-constant-across-a/m-p/517276#M139811</guid>
      <dc:creator>dwhitney</dc:creator>
      <dc:date>2018-11-29T21:42:14Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the frequency/count of a numeric constant across a specific set of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-frequency-count-of-a-numeric-constant-across-a/m-p/517311#M139833</link>
      <description>&lt;P&gt;When something does not run, go to the log, copy the log with the submitted code and any error or warning messages and paste into a code box opened using the forum's {I} icon. The code box is important to maintain formatting of error messages as the message window will reformat text. Many errors will have an _ character on the line below the code to indicate the position SAS determined the error occurred. The message windows will move that character reducing the usefulness of the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since I did not have a data set with 20,000 variables laying around I miscopied the modified smaller example I tested:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of&lt;/P&gt;
&lt;P&gt;&amp;nbsp;HCRU_Other=countc(cats(of string(*),'0');&lt;/P&gt;
&lt;P&gt;try&lt;/P&gt;
&lt;P&gt;&amp;nbsp;HCRU_Other=countc(cats(of string(*)&lt;STRONG&gt;&lt;FONT color="#ff0000"&gt;)&lt;/FONT&gt;&lt;/STRONG&gt;,'0');&lt;/P&gt;
&lt;P&gt;The CATS function wasn't closed.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2018 00:40:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-frequency-count-of-a-numeric-constant-across-a/m-p/517311#M139833</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-11-30T00:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the frequency/count of a numeric constant across a specific set of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-frequency-count-of-a-numeric-constant-across-a/m-p/518390#M140293</link>
      <description>&lt;P&gt;That did it! Thank you very much for the follow up and the help!&lt;/P&gt;</description>
      <pubDate>Tue, 04 Dec 2018 14:09:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-frequency-count-of-a-numeric-constant-across-a/m-p/518390#M140293</guid>
      <dc:creator>dwhitney</dc:creator>
      <dc:date>2018-12-04T14:09:53Z</dc:date>
    </item>
  </channel>
</rss>

