<?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: finding total count in multiple claims record in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/finding-total-count-in-multiple-claims-record/m-p/951693#M371994</link>
    <description>&lt;P&gt;Do you want them counted by the year that is implied by the NAME of the dataset?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming the dataset are already sorted by PATID you could do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data counts;
  if eof then output;
  merge
    test2016(in=flag2016)
    test2017(in=flag2017)
    test2018(in=flag2018)
    test2019(in=flag2019)
    test2020(in=flag2020)
    end=eof
  ;
  by patid;
  if first.patid;
  countall+1;
  array flags [2016:2020] flag: ;
  array counts[2016:2020] count2016-count2020;
  do year=2016 to 2020;
    counts[year]+flags[year];
  end;
  keep count: ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;Obs    countall    count2016    count2017    count2018    count2019    count2020

 1         5           2            3            3            4            5
&lt;/PRE&gt;
&lt;P&gt;Or the YEAR that is implied by the DATE variable in the dataset?&amp;nbsp; Then use SET instead of MERGE and add DTSTART to the BY statement to find their first date.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data counts;
  if eof then output;
  set test2016-test2020 end=eof;
  by patid dtstart;
  countall+first.patid;
  array counts[2016:2021] count2016-count2021 (6*0);
  retain count:;
  if first.patid or year(dtstart) ne lag(year(dtstart)) then 
    counts[year(dtstart)]+1
  ;
  keep count: ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    countall    count2016    count2017    count2018    count2019    count2020    count2021

 1         5           0            1            1            0            3            3

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 23 Nov 2024 01:42:57 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-11-23T01:42:57Z</dc:date>
    <item>
      <title>finding total count in multiple claims record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/finding-total-count-in-multiple-claims-record/m-p/951002#M371819</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a multiple claims from 2016 to 2021. I want to find the total records by (patid) in all the claims without counting any patid twice so I can find the descriptive analysis. For example, In 2016, I want patid=2, In 2017, patid=3, In 2018,patid=3, In 2019, patid=4, In 2020, patid=5.&amp;nbsp; For the Total N, I dont want to count a patid twice so Total N=5 for patid2016-2021&lt;/P&gt;&lt;P&gt;I am not sure how to do this in SAS. Please help. Thanks&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;Data Test2016;  
input patid $ clmid $ dtstart :YYMMDD10.;
format  dtstart YYMMDD10. ; 
datalines;
001 abc 2017-01-01
001 def 2017-02-01 
001 ghi 2017-05-01 
002 xvu 2018-01-01 
002 cde 2018-02-20 
;
run;
Data Test2017;  
input patid $ clmid $ dtstart :YYMMDD10.;
format  dtstart YYMMDD10. ; 
datalines;
001 abc 2017-01-01
001 def 2017-02-01 
001 ghi 2017-05-01 
002 xvu 2018-01-01 
002 cde 2018-02-20 
003 adt 2020-03-25 
003 tyh 2021-01-15 
;
run;
Data Test2018;  
input patid $ clmid $ dtstart :YYMMDD10.;
format  dtstart YYMMDD10. ; 
datalines;
001 abc 2017-01-01
001 def 2017-02-01 
001 ghi 2017-05-01 
002 xvu 2018-01-01 
002 cde 2018-02-20 
003 adt 2020-03-25 
003 tyh 2021-01-15 
;
run;
Data Test2019;  
input patid $ clmid $ dtstart :YYMMDD10.;
format  dtstart YYMMDD10. ; 
datalines;
001 abc 2017-01-01
001 def 2017-02-01 
001 ghi 2017-05-01 
002 xvu 2018-01-01 
002 cde 2018-02-20 
003 adt 2020-03-25 
003 tyh 2021-01-15 
004 wse 2020-03-25 
004 def 2021-01-15 
;
run;
Data Test2020;  
input patid $ clmid $ dtstart :YYMMDD10.;
format  dtstart YYMMDD10. ; 
datalines;
001 abc 2017-01-01
001 def 2017-02-01 
001 ghi 2017-05-01 
002 xvu 2018-01-01 
002 cde 2018-02-20 
003 adt 2020-03-25 
003 tyh 2021-01-15
004 wse 2020-03-25 
004 def 2021-01-15
005 aaa 2020-03-25 
005 bbb 2021-01-15  
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 23:15:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/finding-total-count-in-multiple-claims-record/m-p/951002#M371819</guid>
      <dc:creator>CathyVI</dc:creator>
      <dc:date>2024-11-16T23:15:04Z</dc:date>
    </item>
    <item>
      <title>Re: finding total count in multiple claims record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/finding-total-count-in-multiple-claims-record/m-p/951008#M371820</link>
      <description>&lt;P&gt;Below will write the first occurence of an ID to table WANT. The total of 5 is then simply the number of rows in table want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if _n_=1 then
    do;
      dcl hash h1();
      h1.defineKey('patid');
      h1.defineDone();
    end;

  set test2016 - test2020;

  if h1.check() ne 0 then
    do;
      output;
      h1.add();
    end;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1731805434085.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102288i994D19A933535D25/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1731805434085.png" alt="Patrick_0-1731805434085.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Nov 2024 01:04:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/finding-total-count-in-multiple-claims-record/m-p/951008#M371820</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-11-17T01:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: finding total count in multiple claims record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/finding-total-count-in-multiple-claims-record/m-p/951010#M371821</link>
      <description>&lt;P&gt;So you want desired output to be a dataset or a report ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
set test2016 - test2020 indsname=indsn;
dsn=indsn;
run;
proc sql;
select dsn,count(distinct patid) as n_patid from have group by dsn
union all
select 'Total',count(distinct patid) from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1731806166421.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102289iD37CC1F89C594984/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1731806166421.png" alt="Ksharp_0-1731806166421.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Nov 2024 01:16:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/finding-total-count-in-multiple-claims-record/m-p/951010#M371821</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-11-17T01:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: finding total count in multiple claims record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/finding-total-count-in-multiple-claims-record/m-p/951578#M371963</link>
      <description>&lt;P&gt;Along the lines of&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data need /view=need;
  set test: (keep=patid)  indsname=indsn;
  dsname=indsn;
  if patid^=lag(patid) or dsname^=lag(dsname);
run;
proc freq data=need ;
  tables dsname;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Nov 2024 01:52:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/finding-total-count-in-multiple-claims-record/m-p/951578#M371963</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-11-22T01:52:00Z</dc:date>
    </item>
    <item>
      <title>Re: finding total count in multiple claims record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/finding-total-count-in-multiple-claims-record/m-p/951693#M371994</link>
      <description>&lt;P&gt;Do you want them counted by the year that is implied by the NAME of the dataset?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming the dataset are already sorted by PATID you could do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data counts;
  if eof then output;
  merge
    test2016(in=flag2016)
    test2017(in=flag2017)
    test2018(in=flag2018)
    test2019(in=flag2019)
    test2020(in=flag2020)
    end=eof
  ;
  by patid;
  if first.patid;
  countall+1;
  array flags [2016:2020] flag: ;
  array counts[2016:2020] count2016-count2020;
  do year=2016 to 2020;
    counts[year]+flags[year];
  end;
  keep count: ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;Obs    countall    count2016    count2017    count2018    count2019    count2020

 1         5           2            3            3            4            5
&lt;/PRE&gt;
&lt;P&gt;Or the YEAR that is implied by the DATE variable in the dataset?&amp;nbsp; Then use SET instead of MERGE and add DTSTART to the BY statement to find their first date.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data counts;
  if eof then output;
  set test2016-test2020 end=eof;
  by patid dtstart;
  countall+first.patid;
  array counts[2016:2021] count2016-count2021 (6*0);
  retain count:;
  if first.patid or year(dtstart) ne lag(year(dtstart)) then 
    counts[year(dtstart)]+1
  ;
  keep count: ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    countall    count2016    count2017    count2018    count2019    count2020    count2021

 1         5           0            1            1            0            3            3

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Nov 2024 01:42:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/finding-total-count-in-multiple-claims-record/m-p/951693#M371994</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-23T01:42:57Z</dc:date>
    </item>
  </channel>
</rss>

