<?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 How to get counts on different levels in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-counts-on-different-levels/m-p/629208#M20728</link>
    <description>&lt;P&gt;Hello! I need help with getting counts of how many procedures were done during each admission visit for each. Different patients have different number of admission visits and procedures completed during each visit.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- The number of procedures completed is counted by the amount of times the same admission number is repeated for each enrolid.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data looks like this;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;

input id admission;
datalines;

1&amp;nbsp; &amp;nbsp; 121
1&amp;nbsp; &amp;nbsp; 121
1&amp;nbsp; &amp;nbsp; 121
1&amp;nbsp; &amp;nbsp; 141
1&amp;nbsp; &amp;nbsp; 141
2&amp;nbsp; &amp;nbsp; 111&amp;nbsp; &lt;BR /&gt;;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want an output that shows for each id, how many distinct admission each one had (which I was able to get using code below). But I want for each distinct admission numbers, how many procedures were done at (visit1 - visitn)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I want my output to look like&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output;&lt;/P&gt;&lt;P&gt;id&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; freq&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;visit1&amp;nbsp; &amp;nbsp; &amp;nbsp;visit2&amp;nbsp; &amp;nbsp; &amp;nbsp;visit 3;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was able to get the freq column by using the code below and just using a proc sql to get the max count by each enrolid, but I'm struggling with getting the frequency of the procedures done for each admission. I'll appreciate any help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data x;&lt;BR /&gt;set test;&lt;BR /&gt;by id;&lt;BR /&gt;if first.id then count=0;&lt;BR /&gt;count+1;&lt;BR /&gt;run;&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 03 Mar 2020 18:24:56 GMT</pubDate>
    <dc:creator>JME1</dc:creator>
    <dc:date>2020-03-03T18:24:56Z</dc:date>
    <item>
      <title>How to get counts on different levels</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-counts-on-different-levels/m-p/629208#M20728</link>
      <description>&lt;P&gt;Hello! I need help with getting counts of how many procedures were done during each admission visit for each. Different patients have different number of admission visits and procedures completed during each visit.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- The number of procedures completed is counted by the amount of times the same admission number is repeated for each enrolid.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data looks like this;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;

input id admission;
datalines;

1&amp;nbsp; &amp;nbsp; 121
1&amp;nbsp; &amp;nbsp; 121
1&amp;nbsp; &amp;nbsp; 121
1&amp;nbsp; &amp;nbsp; 141
1&amp;nbsp; &amp;nbsp; 141
2&amp;nbsp; &amp;nbsp; 111&amp;nbsp; &lt;BR /&gt;;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want an output that shows for each id, how many distinct admission each one had (which I was able to get using code below). But I want for each distinct admission numbers, how many procedures were done at (visit1 - visitn)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I want my output to look like&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output;&lt;/P&gt;&lt;P&gt;id&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; freq&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;visit1&amp;nbsp; &amp;nbsp; &amp;nbsp;visit2&amp;nbsp; &amp;nbsp; &amp;nbsp;visit 3;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was able to get the freq column by using the code below and just using a proc sql to get the max count by each enrolid, but I'm struggling with getting the frequency of the procedures done for each admission. I'll appreciate any help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data x;&lt;BR /&gt;set test;&lt;BR /&gt;by id;&lt;BR /&gt;if first.id then count=0;&lt;BR /&gt;count+1;&lt;BR /&gt;run;&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2020 18:24:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-counts-on-different-levels/m-p/629208#M20728</guid>
      <dc:creator>JME1</dc:creator>
      <dc:date>2020-03-03T18:24:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to get counts on different levels</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-counts-on-different-levels/m-p/629324#M20732</link>
      <description>&lt;P&gt;Does this give enough to go forward:&lt;/P&gt;
&lt;PRE&gt;data need;
   set have;
   by notsorted id admission;
   retain procedurenum;

   if first.admission then procedurenum=1;
   else procedurenum+1;
   if last.admission;
run;


&lt;/PRE&gt;
&lt;P&gt;I don't know if your ID and/or admissions are actually sorted so used the NOTSORTED option.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2020 23:24:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-counts-on-different-levels/m-p/629324#M20732</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-03T23:24:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to get counts on different levels</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-counts-on-different-levels/m-p/629400#M20743</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/307430"&gt;@JME1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an approach to achieve this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
	input id admission;
	datalines;
1    121
1    121
1    121
1    141
1    141
2    111  
;
run;

proc sql;
	create table test_freq as
	select id, count(distinct admission) as freq
	from test
	group by id;
quit;

proc freq data=test noprint;
	table admission / out=test_visit (drop=percent);
	by id;
run;

proc transpose data=test_visit out=test_tr (drop=_:) prefix=visit;
	var count;
	by id;	
run;

data want;
	merge test_freq test_tr;
	by id;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Output:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture d’écran 2020-03-04 à 12.59.34.png" style="width: 200px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/36579i03C42FE69EB02C66/image-size/small?v=v2&amp;amp;px=200" role="button" title="Capture d’écran 2020-03-04 à 12.59.34.png" alt="Capture d’écran 2020-03-04 à 12.59.34.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2020 11:59:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-counts-on-different-levels/m-p/629400#M20743</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-03-04T11:59:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to get counts on different levels</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-counts-on-different-levels/m-p/629434#M20744</link>
      <description>Thank you! This worked perfectly.</description>
      <pubDate>Wed, 04 Mar 2020 14:23:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-counts-on-different-levels/m-p/629434#M20744</guid>
      <dc:creator>JME1</dc:creator>
      <dc:date>2020-03-04T14:23:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to get counts on different levels</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-counts-on-different-levels/m-p/629436#M20745</link>
      <description>Thank you for responding &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; ! This helped me get the counts of procedure number done for each admission.</description>
      <pubDate>Wed, 04 Mar 2020 14:25:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-counts-on-different-levels/m-p/629436#M20745</guid>
      <dc:creator>JME1</dc:creator>
      <dc:date>2020-03-04T14:25:36Z</dc:date>
    </item>
  </channel>
</rss>

