<?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: Error with Horizontal Count Variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Error-with-Horizontal-Count-Variable/m-p/717757#M222013</link>
    <description>I don't think that code is doing what you think it's doing. &lt;BR /&gt;&amp;gt;I found it interesting because in some cases the count variable is accurate and other times it is not. Is it because some of the PHYS_ID's include a 1?&lt;BR /&gt;Physician ID as shown would be a character variable and wouldn't be included in the counts.&lt;BR /&gt;&lt;BR /&gt;Additionally, you're checking for the exact value of 1, not if a 1 is contained in the cell. &lt;BR /&gt;&lt;BR /&gt;You can simplify your code as others have shown by simplying adding the values in the M columns. &lt;BR /&gt;&lt;BR /&gt;Count_M = sum(of m:); *will include all variables that start with M;&lt;BR /&gt;count_m = sum(of m1-m26); *if you know the indices you can simplify a bit by listing them.</description>
    <pubDate>Mon, 08 Feb 2021 22:15:05 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-02-08T22:15:05Z</dc:date>
    <item>
      <title>Error with Horizontal Count Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-with-Horizontal-Count-Variable/m-p/717714#M221986</link>
      <description>&lt;P&gt;I'm trying to calculate the number of present values (represented by variables starting with "m") that are identified within each comment.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Each comment can be identified by 3 variables: the comment itself (comment), the physician id (phys_id) and date (comment_date). The subsequent columns are values that define a medical expert, it's a dummy variable that confirms if the comment suggest such variable is practiced by the physician in question.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Currently this is how my code looks, considering the description above :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Picture.JPG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54465iDEF1611B32396B25/image-size/large?v=v2&amp;amp;px=999" role="button" title="Picture.JPG" alt="Picture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To create a count code, I've included the following:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data med_count; 
set med_fnl; 
by phys_id; 
med_cnt = 0; 
array _n(*) _numeric_; 
do i = 1 to dim (_n); 
if _n(i) = 1 then med_cnt + 1; end; run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I found it interesting because in some cases the count variable is accurate and other times it is not. Is it because some of the PHYS_ID's include a 1?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But also, within the same physician (for example; phys_id = 'ASMTO-01') one line has an accurate count of 2 (where 2 columns of medical expert was marked) and the other has an inaccurate count of 2 (where only one column of medical expert was marked). This example is depicted below with a screenshot image of what the table shows. Please note both highlighted rows have a med_cnt = 2.&amp;nbsp;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 756px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54466i221D9BD0132D5F56/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&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;</description>
      <pubDate>Mon, 08 Feb 2021 19:36:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-with-Horizontal-Count-Variable/m-p/717714#M221986</guid>
      <dc:creator>deengyn</dc:creator>
      <dc:date>2021-02-08T19:36:08Z</dc:date>
    </item>
    <item>
      <title>Re: Error with Horizontal Count Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-with-Horizontal-Count-Variable/m-p/717721#M221992</link>
      <description>&lt;P&gt;I don't know if an array is necessary. You can try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data med_fnl;
input comment $1. phys_id $9. comment_date $11. m11 m12 m13 m14 m15 m16 3.;
datalines;
x ASMTO-01 01-12-2011 1 . 1 . .
y ASMTO-01 06-15-2017 1 . 1 . .
z ASMTO-01 04-19-2012 1 . . . .
;
run;

data med_count; 
set med_fnl; 
by phys_id; /* actually don't need this */
	med_cnt2 = sum(of m:);
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It gets the response I think you need, but I only had a limited number of observations that I could replicate in a DATALINES statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit to include my PROC PRINT output.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV class="branch"&gt;
&lt;TABLE class="systitleandfootercontainer" border="0" summary="Page Layout" width="100%" frame="void" rules="none" cellspacing="1" cellpadding="1"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="c systemtitle"&gt;The SAS System&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;BR /&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.MED_COUNT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&gt; &lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;comment&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;phys_id&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;comment_date&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;m11&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;m12&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;m13&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;m14&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;m15&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;m16&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;med_cnt2&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="l data"&gt;x&lt;/TD&gt;
&lt;TD class="l data"&gt;ASMTO-01&lt;/TD&gt;
&lt;TD class="l data"&gt;01-12-2011&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="l data"&gt;y&lt;/TD&gt;
&lt;TD class="l data"&gt;ASMTO-01&lt;/TD&gt;
&lt;TD class="l data"&gt;06-15-2017&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="l data"&gt;z&lt;/TD&gt;
&lt;TD class="l data"&gt;ASMTO-01&lt;/TD&gt;
&lt;TD class="l data"&gt;04-19-2012&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Mon, 08 Feb 2021 21:34:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-with-Horizontal-Count-Variable/m-p/717721#M221992</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-02-08T21:34:13Z</dc:date>
    </item>
    <item>
      <title>Re: Error with Horizontal Count Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-with-Horizontal-Count-Variable/m-p/717725#M221994</link>
      <description>&lt;P&gt;Usually DATE is a numeric variable. I suppose in your case data is a string otherwise the summary will have 5 digits.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any other numeric variable except those wanted variables :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want to sum sum only those variables where value=1 or any value of those variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I ran your code on a dummy test data in two different methods and got the same summary:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id $ m1 m2 m3;
cards;
A 1 . 1
B 1 1 1 
C . 1 1
; run;
data sum;
 set have;
     array _n {*} _numeric_;
     sum=0;
     do i=1 to dim(_n);
        if _n(i) = 1 then sum+1;
     end;
     drop i;
run;

data sum1;
 set have;
     sum = sum(of m:);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Feb 2021 20:16:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-with-Horizontal-Count-Variable/m-p/717725#M221994</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-02-08T20:16:02Z</dc:date>
    </item>
    <item>
      <title>Re: Error with Horizontal Count Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-with-Horizontal-Count-Variable/m-p/717757#M222013</link>
      <description>I don't think that code is doing what you think it's doing. &lt;BR /&gt;&amp;gt;I found it interesting because in some cases the count variable is accurate and other times it is not. Is it because some of the PHYS_ID's include a 1?&lt;BR /&gt;Physician ID as shown would be a character variable and wouldn't be included in the counts.&lt;BR /&gt;&lt;BR /&gt;Additionally, you're checking for the exact value of 1, not if a 1 is contained in the cell. &lt;BR /&gt;&lt;BR /&gt;You can simplify your code as others have shown by simplying adding the values in the M columns. &lt;BR /&gt;&lt;BR /&gt;Count_M = sum(of m:); *will include all variables that start with M;&lt;BR /&gt;count_m = sum(of m1-m26); *if you know the indices you can simplify a bit by listing them.</description>
      <pubDate>Mon, 08 Feb 2021 22:15:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-with-Horizontal-Count-Variable/m-p/717757#M222013</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-02-08T22:15:05Z</dc:date>
    </item>
    <item>
      <title>Re: Error with Horizontal Count Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-with-Horizontal-Count-Variable/m-p/717763#M222017</link>
      <description>Yes, I found it weird too.&lt;BR /&gt;I was considering it could be the phys_id, but it's very inconsistent.&lt;BR /&gt;&lt;BR /&gt;I've tried the "Count_M = sum(of m:)" code and it works, thank you!</description>
      <pubDate>Mon, 08 Feb 2021 22:43:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-with-Horizontal-Count-Variable/m-p/717763#M222017</guid>
      <dc:creator>deengyn</dc:creator>
      <dc:date>2021-02-08T22:43:31Z</dc:date>
    </item>
    <item>
      <title>Re: Error with Horizontal Count Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-with-Horizontal-Count-Variable/m-p/717996#M222123</link>
      <description>&lt;P&gt;Yes, I was only looking at when the&amp;nbsp;&lt;SPAN&gt;value=1 (the only option was 1 or . for this dataset).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;However, I'm curious how would the code change if it was to look specifically at 1's.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;(i.e. to identify columns that specifically state 1 should other columns also include other numbers as shown below)&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;data have;
  input id $ m1 m2 m3 m4 m5;
cards;
A 1 . 1 2 .
B 1 1 1 2 1 
C . 1 1 2 2
; run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 19:58:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-with-Horizontal-Count-Variable/m-p/717996#M222123</guid>
      <dc:creator>deengyn</dc:creator>
      <dc:date>2021-02-09T19:58:34Z</dc:date>
    </item>
  </channel>
</rss>

