<?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: How do I count the number of observations per unique ID conditional on a variable? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-count-the-number-of-observations-per-unique-ID/m-p/621076#M19590</link>
    <description>&lt;P&gt;Hi Asgee,&lt;/P&gt;&lt;P&gt;You can use proc SQL to keep only the repeating ids and then use Proc Freq to get the count of ID's.&lt;/P&gt;&lt;PRE&gt;data have;
input id $ date_test:mmddyy8. test_Date;
format date_test mmddyy8.;
datalines;
ABC 01/08/2020 0.231
ABC 02/02/2020 0.523
ABC 03/04/2020 0.146
GG 01/15/2020 0.875
GG 02/14/2020 0.345
DEF 01/11/2020 0.383
DEF 02/05/2020 0.825
LIN 01/30/2020 0.622
;
run;

proc sort data=have nouniquekeys out=alldups uniqueout=uniques;
 by id;
run;
proc freq data=alldups noprint;                                                                                                                              
 tables id / out=want(drop=percent);                                                                                                  
run;&lt;/PRE&gt;&lt;P&gt;Hope this helps. Check out&amp;nbsp; my article on &lt;A title="Proc Sort" href="https://9to5sas.com/proc-sort/" target="_self"&gt;Proc Sort&lt;/A&gt;.&lt;/P&gt;</description>
    <pubDate>Thu, 30 Jan 2020 07:57:59 GMT</pubDate>
    <dc:creator>subhroster</dc:creator>
    <dc:date>2020-01-30T07:57:59Z</dc:date>
    <item>
      <title>How do I count the number of observations per unique ID conditional on a variable?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-count-the-number-of-observations-per-unique-ID/m-p/620921#M19565</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This seems like a super basic question but I'm working on a project where there are some IDs with repeated observations over time. My current data looks something like this:&am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t;&lt;P&gt;0.345&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;DEF&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;01_11_2020&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0.383&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;DEF&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;02_05_2020&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0.825&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;LIN&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;01_30_2020&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0.622&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want to know is which of the ID's have&amp;nbsp;&lt;STRONG&gt;2 or more&amp;nbsp;&lt;/STRONG&gt;testing data. I'm less concerned about knowing which particular ID's they are, but more on knowing what is the total # of ID's in the dataset that have 2 or more testing data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to run the code below but I don't think it's correct considering it's selecting the true testing data value and not the count:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data = master;
where test_data &amp;gt;=2;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If there was a way I can select and know which particular observations and how many testing data they have, that would be really helpful. Thanks in advance!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jan 2020 17:40:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-count-the-number-of-observations-per-unique-ID/m-p/620921#M19565</guid>
      <dc:creator>asgee</dc:creator>
      <dc:date>2020-01-29T17:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do I count the number of observations per unique ID conditional on a variable?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-count-the-number-of-observations-per-unique-ID/m-p/620928#M19566</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;
input id $ Date_Test :mmddyy10. Test_Data;
format date_test mmddyy10.;
cards;
ABC
01_08_2020
0.231
ABC
02_02_2020
0.523
ABC
03_04_2020
0.146
GG
01_15_2020
0.875
GG
02_14_2020
0.345
DEF
01_11_2020
0.383
DEF
02_05_2020
0.825
LIN
01_30_2020
0.622
;

proc sql;
create table want as
select count( id) as want
from (select distinct id from have group by id having count(test_data)&amp;gt;=2);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Jan 2020 18:00:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-count-the-number-of-observations-per-unique-ID/m-p/620928#M19566</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-29T18:00:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do I count the number of observations per unique ID conditional on a variable?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-count-the-number-of-observations-per-unique-ID/m-p/620930#M19567</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input id $ Date_Test :mmddyy10. Test_Data;
format date_test mmddyy10.;
cards;
ABC
01_08_2020
0.231
ABC
02_02_2020
0.523
ABC
03_04_2020
0.146
GG
01_15_2020
0.875
GG
02_14_2020
0.345
DEF
01_11_2020
0.383
DEF
02_05_2020
0.825
LIN
01_30_2020
0.622
;
run;


data master;
cnt=0;
	do _n_=1 by 1 until(last.id);
		set have;
		by id notsorted;
		cnt+1;
	end;

	do _n_=1 to _n_ ;
		set have;
		output;
	end;
run;

proc print data = master;
var id Date_Test Test_Data;
where cnt &amp;gt;=2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Jan 2020 18:11:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-count-the-number-of-observations-per-unique-ID/m-p/620930#M19567</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2020-01-29T18:11:29Z</dc:date>
    </item>
    <item>
      <title>Re: How do I count the number of observations per unique ID conditional on a variable?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-count-the-number-of-observations-per-unique-ID/m-p/620967#M19573</link>
      <description>&lt;P&gt;I just have a quick question re: the table that's produced based on your code. So firstly it shouldn't display any ID's of people with only 1 test_data right? Second, I see that it does list subjects which have multiple instances of test_data. But if say the subject appears 3 times in this table, does this display the 1st observation/row for this subject?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Reality:&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp;Test_Data&lt;/P&gt;&lt;P&gt;AD&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 13&lt;/P&gt;&lt;P&gt;GG&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;123&lt;/P&gt;&lt;P&gt;GG&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 33&lt;/P&gt;&lt;P&gt;GG&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 72&lt;/P&gt;&lt;P&gt;DF&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;89&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What your code produces (?):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1)&amp;nbsp;&lt;/P&gt;&lt;P&gt;GG&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;33&amp;nbsp;&lt;/P&gt;&lt;P&gt;GG&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;72&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OR&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2)&amp;nbsp;&lt;/P&gt;&lt;P&gt;GG 123&lt;/P&gt;&lt;P&gt;GG 33&lt;/P&gt;&lt;P&gt;GG 72&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just wanted to double check. Thanks again for the help!&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jan 2020 19:49:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-count-the-number-of-observations-per-unique-ID/m-p/620967#M19573</guid>
      <dc:creator>asgee</dc:creator>
      <dc:date>2020-01-29T19:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I count the number of observations per unique ID conditional on a variable?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-count-the-number-of-observations-per-unique-ID/m-p/620973#M19575</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/308380"&gt;@asgee&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I just have a quick question re: the table that's produced based on your code. So firstly it shouldn't display any ID's of people with only 1 test_data right? Second, I see that it does list subjects which have multiple instances of test_data. But if say the subject appears 3 times in this table, does this display the 1st observation/row for this subject?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Reality:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp;Test_Data&lt;/P&gt;
&lt;P&gt;AD&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 13&lt;/P&gt;
&lt;P&gt;GG&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;123&lt;/P&gt;
&lt;P&gt;GG&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 33&lt;/P&gt;
&lt;P&gt;GG&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 72&lt;/P&gt;
&lt;P&gt;DF&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;89&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What your code produces (?):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;GG&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;33&amp;nbsp;&lt;/P&gt;
&lt;P&gt;GG&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;72&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OR&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;GG 123&lt;/P&gt;
&lt;P&gt;GG 33&lt;/P&gt;
&lt;P&gt;GG 72&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just wanted to double check. Thanks again for the help!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You'll learn more if you test the code with modified input data.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jan 2020 19:56:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-count-the-number-of-observations-per-unique-ID/m-p/620973#M19575</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-01-29T19:56:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do I count the number of observations per unique ID conditional on a variable?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-count-the-number-of-observations-per-unique-ID/m-p/620975#M19576</link>
      <description>&lt;P&gt;Nvm yes you're right, just tested it myself and figured out how the code works.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jan 2020 20:00:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-count-the-number-of-observations-per-unique-ID/m-p/620975#M19576</guid>
      <dc:creator>asgee</dc:creator>
      <dc:date>2020-01-29T20:00:05Z</dc:date>
    </item>
    <item>
      <title>Re: How do I count the number of observations per unique ID conditional on a variable?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-count-the-number-of-observations-per-unique-ID/m-p/621076#M19590</link>
      <description>&lt;P&gt;Hi Asgee,&lt;/P&gt;&lt;P&gt;You can use proc SQL to keep only the repeating ids and then use Proc Freq to get the count of ID's.&lt;/P&gt;&lt;PRE&gt;data have;
input id $ date_test:mmddyy8. test_Date;
format date_test mmddyy8.;
datalines;
ABC 01/08/2020 0.231
ABC 02/02/2020 0.523
ABC 03/04/2020 0.146
GG 01/15/2020 0.875
GG 02/14/2020 0.345
DEF 01/11/2020 0.383
DEF 02/05/2020 0.825
LIN 01/30/2020 0.622
;
run;

proc sort data=have nouniquekeys out=alldups uniqueout=uniques;
 by id;
run;
proc freq data=alldups noprint;                                                                                                                              
 tables id / out=want(drop=percent);                                                                                                  
run;&lt;/PRE&gt;&lt;P&gt;Hope this helps. Check out&amp;nbsp; my article on &lt;A title="Proc Sort" href="https://9to5sas.com/proc-sort/" target="_self"&gt;Proc Sort&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 07:57:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-count-the-number-of-observations-per-unique-ID/m-p/621076#M19590</guid>
      <dc:creator>subhroster</dc:creator>
      <dc:date>2020-01-30T07:57:59Z</dc:date>
    </item>
  </channel>
</rss>

