<?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: Number of visit per patient in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Number-of-visit-per-patient/m-p/876155#M346192</link>
    <description>&lt;P&gt;I suppose you want to do something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do i = 1 by 1 until (last.id);
    set have; by id;
    end;

length v $16;
select (i);
    when (1) v = "1 visit";
    when (2) v = "2 visits";
    otherwise v = "3 visits or more";
    end;
    
drop i visit;
rename v = visit;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 17 May 2023 03:21:59 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2023-05-17T03:21:59Z</dc:date>
    <item>
      <title>Number of visit per patient</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Number-of-visit-per-patient/m-p/876142#M346188</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I will like to know the number of visit per patient and group visit in to "1 visit", "2 visit" or "3 visit or more".&lt;/P&gt;&lt;P&gt;I am getting stuck with my code and will appreciate any help.&lt;/P&gt;&lt;P&gt;Here is a sample data;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data readin;
input ID 1-6 Name$ 7-14  visit MMDDYY10.;
format visit MMDDYY10.;
cards;
1     David   4/5/2001
1     David   7/4/2001
2     Sam     4/5/2004
2     Sam     5/4/2005
3     Bane    8/7/2004
3     Bane    9/2/2010
3     Bane    8/7/2003
4     Dane    2/3/2003
4     Dane    8/7/2005
5     Ken     8/7/2006
5     Ken     6/3/2006
6     Priya   7/2/2009
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;For example if a patient have 1 visit then visit=1. in this case priya has 1 visit but david has 2 visit so visit=2 and so on.&lt;/P&gt;&lt;P&gt;I tried using first.id and last.id but i got stuck.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data want;
 set have;
 by id;
 if first.id then visit = 1;
 else visit + 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2023 01:21:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Number-of-visit-per-patient/m-p/876142#M346188</guid>
      <dc:creator>CathyVI</dc:creator>
      <dc:date>2023-05-17T01:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: Number of visit per patient</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Number-of-visit-per-patient/m-p/876155#M346192</link>
      <description>&lt;P&gt;I suppose you want to do something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do i = 1 by 1 until (last.id);
    set have; by id;
    end;

length v $16;
select (i);
    when (1) v = "1 visit";
    when (2) v = "2 visits";
    otherwise v = "3 visits or more";
    end;
    
drop i visit;
rename v = visit;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 May 2023 03:21:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Number-of-visit-per-patient/m-p/876155#M346192</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2023-05-17T03:21:59Z</dc:date>
    </item>
    <item>
      <title>Re: Number of visit per patient</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Number-of-visit-per-patient/m-p/876169#M346198</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value visits
  1 = "1 visit"
  2 = "2 visits"
  other = "3 or more visits"
;
run;

proc sql;
create table want as
  select
    id,
    name,
    count(*) as visit format=visits.
  from readin
  group by id, name
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 May 2023 06:38:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Number-of-visit-per-patient/m-p/876169#M346198</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-17T06:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: Number of visit per patient</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Number-of-visit-per-patient/m-p/876299#M346228</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp; Thank you. Although i agreed to the solution however, I mad a mistake in my data representation so when I tried&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;code I got a different result. My mistake was from my ID. This is the right format from 1 - 12&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data readin;
input ID 1-6 Name$ 7-14  visit MMDDYY10.;
format visit MMDDYY10.;
cards;
1     David   4/5/2001
2     David   7/4/2001
3     Sam     4/5/2004
4     Sam     5/4/2005
5     Bane    8/7/2004
6     Bane    9/2/2010
7     Bane    8/7/2003
8     Dane    2/3/2003
9     Dane    8/7/2005
10    Ken     8/7/2006
11    Ken     6/3/2006
12    Priya   7/2/2009
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 May 2023 18:16:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Number-of-visit-per-patient/m-p/876299#M346228</guid>
      <dc:creator>CathyVI</dc:creator>
      <dc:date>2023-05-17T18:16:02Z</dc:date>
    </item>
    <item>
      <title>Re: Number of visit per patient</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Number-of-visit-per-patient/m-p/876304#M346229</link>
      <description>&lt;P&gt;Both codes can accomodate this change:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data wantPG;
do i = 1 by 1 until (last.name);
    set readin; by name notsorted;
    end;

length v $16;
select (i);
    when (1) v = "1 visit";
    when (2) v = "2 visits";
    otherwise v = "3 visits or more";
    end;
    
drop i visit;
rename v = visit;
run;

proc format;
value visits
  1 = "1 visit"
  2 = "2 visits"
  other = "3 or more visits"
;
run;

proc sql;
create table wantKB as
  select
    max(id) as maxId,
    name,
	max(visit) as lastVisit format=mmddyy10.,
    count(*) as visit format=visits.
  from readin
  group by name
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 May 2023 19:06:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Number-of-visit-per-patient/m-p/876304#M346229</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2023-05-17T19:06:33Z</dc:date>
    </item>
  </channel>
</rss>

