<?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: Duplicate ID question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Duplicate-ID-question/m-p/916980#M361197</link>
    <description>&lt;P&gt;Alternatively, you can use COUNT(DISTINCT ...) in PROC SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select comb, count(distinct id) as n from
  (select id, compress(cat(max(type=1),2*max(type=2),3*max(type=3)),'0') as comb 
   from have
   group by id)
group by comb
order by input(comb,3.);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 20 Feb 2024 15:05:17 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2024-02-20T15:05:17Z</dc:date>
    <item>
      <title>Duplicate ID question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Duplicate-ID-question/m-p/916975#M361195</link>
      <description>&lt;P&gt;I have a table like below, there are only 4 distinct IDs but have 6 observations. I'd like to count how many people are in type 1 only, in type 2 only, in type 3 only, and in Combination of 3 types...&lt;/P&gt;
&lt;P&gt;Is there a code capable of fulfilling this process?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;
&lt;P&gt;&lt;STRONG&gt;ID&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;&lt;STRONG&gt;Type&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;&lt;STRONG&gt;Length&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;108&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;2&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;54&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;3&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;87&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;2&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;46&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;3&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;93&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;4&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;2&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;
&lt;P&gt;29&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Tue, 20 Feb 2024 14:17:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Duplicate-ID-question/m-p/916975#M361195</guid>
      <dc:creator>LarissaW</dc:creator>
      <dc:date>2024-02-20T14:17:14Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate ID question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Duplicate-ID-question/m-p/916979#M361196</link>
      <description>&lt;P&gt;I guess what you want is to make a profile of each ID&amp;nbsp; (7 profiles possibles: 3 single types, 3 pairs, and 1 triple), and then do a frequency of those profiles.&amp;nbsp; &amp;nbsp;But then what do you want to do about the LENGTH variable?&amp;nbsp; Is it to be aggregated? averaged? ignored?&amp;nbsp; Or do you simply want a frequency of profiles?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code below does nothing but report the frequency of each type-profile:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID Type	Length;
datalines;
1	1	108
1	2	54
1	3	87
2	1	46
3	1	93
4	2	29
run;

data profiles (keep=id type1-type3); 
  do until (last.id);
    set have;
    by id;
    array dummy {3} type1-type3;
    dummy{type}=1;
    if first.id then put id= ;
  end;
  do _n_=1 to dim(dummy);
    if dummy{_n_}=. then dummy{_n_}=0;
  end;
run; 
proc freq data=profiles;
  table type1*type2*type3 / list;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if you are interested in corresponding statistics about other vars, like LENGTH, you have to describe what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW: this code assumes that your data are sorted by ID.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2024 15:02:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Duplicate-ID-question/m-p/916979#M361196</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-02-20T15:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate ID question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Duplicate-ID-question/m-p/916980#M361197</link>
      <description>&lt;P&gt;Alternatively, you can use COUNT(DISTINCT ...) in PROC SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select comb, count(distinct id) as n from
  (select id, compress(cat(max(type=1),2*max(type=2),3*max(type=3)),'0') as comb 
   from have
   group by id)
group by comb
order by input(comb,3.);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Feb 2024 15:05:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Duplicate-ID-question/m-p/916980#M361197</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-02-20T15:05:17Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate ID question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Duplicate-ID-question/m-p/916988#M361201</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id type length;
cards;
1	1	108
1	2	54
1	3	87
2	1	46
3	1	93
4	2	29
;

proc transpose data=have out=have_t;
    by id;
    var type;
run;

data want;
    set have_t;
    length category $ 10;
    call sortn(of col:);
    category=compress(cats(of col:),'.');
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Feb 2024 18:16:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Duplicate-ID-question/m-p/916988#M361201</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-02-20T18:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate ID question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Duplicate-ID-question/m-p/917014#M361209</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/427928"&gt;@LarissaW&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;I see you what are looking for is "&lt;SPAN&gt;I'd like to count how many people are in type 1 only, in type 2 only, in type 3 only, and in Combination of 3 types..."&lt;BR /&gt;The following code create two tables Types for the first case and combinations for the second case.&amp;nbsp;&lt;BR /&gt;The table Types answers&amp;nbsp;the question how many users there in a are&amp;nbsp;given type?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The table Combination answers the question&amp;nbsp; &amp;nbsp;in how many type's is a user present.?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id type length;
cards;
1 1 108
1 2 54
1 3 87
2 1 46
3 1 93
4 2 29
;
proc sql;
create table Type as
Select TYPE,Count(ID) as users from have
group by Type
order by Type;
Create table combination as
Select ID, Count(Type) as TYPES from have
group by ID
order by ID;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2024 17:44:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Duplicate-ID-question/m-p/917014#M361209</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2024-02-20T17:44:08Z</dc:date>
    </item>
  </channel>
</rss>

