<?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 count how many patients available at each visit given their study duration time in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/count-how-many-patients-available-at-each-visit-given-their/m-p/570337#M160805</link>
    <description>&lt;P&gt;Patients visit at month in first 6 months and then every 3 months after that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    input id $ time; /* time is study duration, unit is month,  */
    datalines;
        1 1.5
        2 3.4
        3 5.6
        4 9.8
        5 13.2
        6 2.5
        7 10.1
        8 15.6
        9 7.5
        10 21.1;
RUN;

/* each cycle is a month; want to know how many patients at each cycle */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What I want is like below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    cycle1  10 /* 10 patients alive at end of 1st month */
    cycle2  9  /* 9 alive at end of 2nd month */
    cycle3  8
    cycle4  7
    cycle5  7
    cycle6  6
    cycle9  5 /* after first 6 months, patients visit every 3 months */
    cycle12 3
    cycle15 2
    cycle18 1
    cycle21 1
    cycle24 0 /* if there is time &amp;gt;27, then cycle27 has value 0 */
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;My current idea is using select in proc sql:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table want as
    select count(id) into: cycle1 from have where time&amp;gt;=1;
    select count(id) into: cycle2 from have where time&amp;gt;=2;
... 
    select count(id) into: cycle6 from have where time&amp;gt;=6;
    select count(id) into: cycle9 from have where time&amp;gt;=9;
    select count(id) into: cycle12 from have where time&amp;gt;=12;
    ...
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I need to determine the last cycle. Maybe something like: last cycle = int(max(time)/3)*3&lt;/P&gt;</description>
    <pubDate>Mon, 01 Jul 2019 18:32:39 GMT</pubDate>
    <dc:creator>fengyuwuzu</dc:creator>
    <dc:date>2019-07-01T18:32:39Z</dc:date>
    <item>
      <title>count how many patients available at each visit given their study duration time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-how-many-patients-available-at-each-visit-given-their/m-p/570337#M160805</link>
      <description>&lt;P&gt;Patients visit at month in first 6 months and then every 3 months after that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    input id $ time; /* time is study duration, unit is month,  */
    datalines;
        1 1.5
        2 3.4
        3 5.6
        4 9.8
        5 13.2
        6 2.5
        7 10.1
        8 15.6
        9 7.5
        10 21.1;
RUN;

/* each cycle is a month; want to know how many patients at each cycle */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What I want is like below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    cycle1  10 /* 10 patients alive at end of 1st month */
    cycle2  9  /* 9 alive at end of 2nd month */
    cycle3  8
    cycle4  7
    cycle5  7
    cycle6  6
    cycle9  5 /* after first 6 months, patients visit every 3 months */
    cycle12 3
    cycle15 2
    cycle18 1
    cycle21 1
    cycle24 0 /* if there is time &amp;gt;27, then cycle27 has value 0 */
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;My current idea is using select in proc sql:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table want as
    select count(id) into: cycle1 from have where time&amp;gt;=1;
    select count(id) into: cycle2 from have where time&amp;gt;=2;
... 
    select count(id) into: cycle6 from have where time&amp;gt;=6;
    select count(id) into: cycle9 from have where time&amp;gt;=9;
    select count(id) into: cycle12 from have where time&amp;gt;=12;
    ...
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I need to determine the last cycle. Maybe something like: last cycle = int(max(time)/3)*3&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 18:32:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-how-many-patients-available-at-each-visit-given-their/m-p/570337#M160805</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2019-07-01T18:32:39Z</dc:date>
    </item>
    <item>
      <title>Re: count how many patients available at each visit given their study duration time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-how-many-patients-available-at-each-visit-given-their/m-p/570378#M160819</link>
      <description>&lt;P&gt;Honestly speaking, I am not clear with what is the relationship between have and want datasets in this case. So not sure if this one will fit your bill. This code creates how many patients survived &lt;STRONG&gt;at the start/end&lt;/STRONG&gt; of the month(depending upon the rounding off). Please let me know if this is what you wanted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    INPUT id $ time; /* time is study duration, unit is month,  */
    DATALINES;
        1 1.5
        2 3.4
        3 5.6
        4 9.8
        5 13.2
        6 2.5
        7 10.1
        8 15.6
        9 7.5
        10 21.1;
RUN;

DATA Processed;
	SET have;
	Month = ROUND(time);
RUN;

PROC SQL;
	SELECT COUNT(*) INTO :TotalRows FROM Processed ;
QUIT;

PROC REPORT DATA=Processed;
	COLUMNS Month Month=Survived TotalSurvived;
	DEFINE MONTH / GROUP;
	DEFINE Survived / ANALYSIS N NOPRINT;
	DEFINE TotalSurvived / COMPUTED;
	COMPUTE BEFORE;
		TotalPresent = &amp;amp;TotalRows;
	ENDCOMP;
	COMPUTE TotalSurvived;
		TotalPresent = TotalPresent - _C2_;
		TotalSurvived = TotalPresent;
	ENDCOMP;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Output is as below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Output" style="width: 150px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/30694i52DF5C9E6AFBBFAA/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot from 2019-07-02 01-24-43.png" alt="Output" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Output&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 19:57:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-how-many-patients-available-at-each-visit-given-their/m-p/570378#M160819</guid>
      <dc:creator>koyelghosh</dc:creator>
      <dc:date>2019-07-01T19:57:43Z</dc:date>
    </item>
    <item>
      <title>Re: count how many patients available at each visit given their study duration time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-how-many-patients-available-at-each-visit-given-their/m-p/570387#M160824</link>
      <description>&lt;P&gt;Thank you, &lt;SPAN class="UserName lia-user-name lia-user-rank-Contributor"&gt;&lt;A id="link_8" class="lia-link-navigation lia-page-link lia-user-name-link" style="color: #007dc3;" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212247" target="_self"&gt;&lt;SPAN class=""&gt;koyelghosh&lt;/SPAN&gt;&lt;/A&gt;&lt;/SPAN&gt;, for your help. It is helpful but not exactly what I want. Sorry I did not make it clearer.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Patients will visit every month in first 6 months, and after that every 3 months, i.e. after 6 months, I only count every 3 months, like 9, 12, 15 months etc. Based on the sample data, I want something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Month&amp;nbsp;&amp;nbsp; count&lt;/P&gt;
&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&lt;/P&gt;
&lt;P&gt;2&amp;nbsp;&amp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1&lt;/P&gt;
&lt;P&gt;24&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 20:35:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-how-many-patients-available-at-each-visit-given-their/m-p/570387#M160824</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2019-07-01T20:35:23Z</dc:date>
    </item>
    <item>
      <title>Re: count how many patients available at each visit given their study duration time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-how-many-patients-available-at-each-visit-given-their/m-p/570446#M160850</link>
      <description>&lt;P&gt;I am sure that a shorter solution is possible, but i can't spend more time on finding it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ByMonth;
   set have;

   length Month 8;

   do Month = 1 to min(int(time), 6);
      output;
   end;

   if int(time) &amp;gt;= 9 then do;
      do Month = 9 to int(time) by 3;
         output;
      end;
   end;
run;

proc summary data=ByMonth nway;
   class Month;
   output out=Counted(drop=_type_ rename=(_freq_=count));
run;

data want;
   set counted end=lastObs;

   output;

   if lastObs then do;
      Month = Month + 3;
      Count = 0;
      output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Jul 2019 06:51:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-how-many-patients-available-at-each-visit-given-their/m-p/570446#M160850</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-07-02T06:51:19Z</dc:date>
    </item>
  </channel>
</rss>

