<?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 to create an enrollment array using start date and end date? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-enrollment-array-using-start-date-and-end-date/m-p/737520#M229947</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/372151"&gt;@rdum96&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I'm trying to get a total count for each month. I'm new to this so I'm prolly not thinking the right way. Would appreciate your help&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Could you please state clearly the desired output? Could you please give a realistic example of the input data set (not just two records) that covers the real-world examples that might occur in your data, and the output from that example data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Again, arrays are not the way to get total counts by month.&lt;/P&gt;</description>
    <pubDate>Wed, 28 Apr 2021 09:53:23 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-04-28T09:53:23Z</dc:date>
    <item>
      <title>How to create an enrollment array using start date and end date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-enrollment-array-using-start-date-and-end-date/m-p/737444#M229905</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm trying to get if someone is enrolled in a program for each month from Jan 2020 to Feb 2021. So I'm interested in an array with month_1 to month_14.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data is something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Start_date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end_date&lt;/P&gt;&lt;P&gt;011&amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/1996&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5/3/2020&lt;/P&gt;&lt;P&gt;003&amp;nbsp; &amp;nbsp; &amp;nbsp; 2/1/2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12/1/2020&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So typically the output I'm looking for is&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Start_date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end_date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; month_1&amp;nbsp; month_2&amp;nbsp; month_3 month_4...............................&lt;/P&gt;&lt;P&gt;011&amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/1996&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5/3/2020&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; &amp;nbsp; &amp;nbsp; 1&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; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp;&lt;/P&gt;&lt;P&gt;003&amp;nbsp; &amp;nbsp; &amp;nbsp; 2/1/2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12/1/2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &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; 1&amp;nbsp; &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; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would love some help on this!&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 21:22:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-enrollment-array-using-start-date-and-end-date/m-p/737444#M229905</guid>
      <dc:creator>rdum96</dc:creator>
      <dc:date>2021-04-27T21:22:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an enrollment array using start date and end date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-enrollment-array-using-start-date-and-end-date/m-p/737445#M229906</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/372151"&gt;@rdum96&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I'm trying to get if someone is enrolled in a program for each month from Jan 2020 to Feb 2021. So I'm interested in an array with month_1 to month_14.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data is something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Start_date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end_date&lt;/P&gt;
&lt;P&gt;011&amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/1996&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5/3/2020&lt;/P&gt;
&lt;P&gt;003&amp;nbsp; &amp;nbsp; &amp;nbsp; 2/1/2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12/1/2020&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So typically the output I'm looking for is&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Start_date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end_date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; month_1&amp;nbsp; month_2&amp;nbsp; month_3 month_4...............................&lt;/P&gt;
&lt;P&gt;011&amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/1996&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5/3/2020&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; &amp;nbsp; &amp;nbsp; 1&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; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp;&lt;/P&gt;
&lt;P&gt;003&amp;nbsp; &amp;nbsp; &amp;nbsp; 2/1/2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12/1/2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &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; 1&amp;nbsp; &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; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would love some help on this!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is an incredibly poor choice of data layout, that will make your programming more difficult; and almost never necessary. No array is necessary to determine if "someone is enrolled in a program for each month from Jan 2020 to Feb 2021". &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To answer that qestion, how about this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
     set have;
     if start_date&amp;lt;='01JAN2020'd and end_date&amp;gt;='01FEB2021'd then result=1;
     else result=0
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Apr 2021 21:31:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-enrollment-array-using-start-date-and-end-date/m-p/737445#M229906</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-27T21:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an enrollment array using start date and end date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-enrollment-array-using-start-date-and-end-date/m-p/737448#M229909</link>
      <description>I'm trying to get a total count for each month. I'm new to this so I'm prolly not thinking the right way. Would appreciate your help</description>
      <pubDate>Tue, 27 Apr 2021 21:30:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-enrollment-array-using-start-date-and-end-date/m-p/737448#M229909</guid>
      <dc:creator>rdum96</dc:creator>
      <dc:date>2021-04-27T21:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an enrollment array using start date and end date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-enrollment-array-using-start-date-and-end-date/m-p/737451#M229912</link>
      <description>So I would need to include people who joined somewhere in the middle of the year or left in the middle too. I think this would include only people enrolled during the entire spell?</description>
      <pubDate>Tue, 27 Apr 2021 21:34:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-enrollment-array-using-start-date-and-end-date/m-p/737451#M229912</guid>
      <dc:creator>rdum96</dc:creator>
      <dc:date>2021-04-27T21:34:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an enrollment array using start date and end date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-enrollment-array-using-start-date-and-end-date/m-p/737456#M229916</link>
      <description>&lt;P&gt;Add an actual DATE variable.&amp;nbsp; Then use a proper date format to make nice appearing values.&lt;/P&gt;
&lt;P&gt;This creates a Have data that looks like your "example" (Hint: data steps are the best way to show values so we can code against them.)&lt;/P&gt;
&lt;P&gt;Then adds a date that is the first day of the month in the interval you asked for.&lt;/P&gt;
&lt;P&gt;Since your "month" values contained 0/1 coded values I have added a random value that takes 0/1 values.&lt;/P&gt;
&lt;P&gt;Then show use of Proc Summary to create a data set for the sum of 1's which I think you imply as the desired result.&lt;/P&gt;
&lt;P&gt;Proc Report or Tabulate could make nice tables of either the sums or the counts for each of 1 and 0.&lt;/P&gt;
&lt;PRE&gt;data have;
  input ID $ Start_date :mmddyy10.  end_date :mmddyy10.;
  format start_date end_date mmddyy10.;
datalines;
011      1/1/1996               5/3/2020
003      2/1/2020               12/1/2020
;

data want;
   set have;
   do date = '01Jan2020'd to '01Feb2021'd ;
      randomvalue = rand('bernoulli',.5);
      output;
      date=intnx('month',date,1,'B');
   end;
   format date yymon7.;
run;

/* how to sum (count) 1/0 variable by calendar month*/
proc summary data=want nway;
   class date;
   format date yymon7.;
   var randomvalue;
   output out=summary (drop=_:) sum=sumrandvalues;
run;&lt;/PRE&gt;
&lt;P&gt;When dealing with dates it is almost always a good idea to use actual SAS date values. Formats can create groups that will be honored by analysis, reporting or graphing procedures. The functions INTNX and INTCK can increment or determine intervals between dates (and times or datetimes).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt; has a PDF with much information about dates.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 21:48:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-enrollment-array-using-start-date-and-end-date/m-p/737456#M229916</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-27T21:48:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an enrollment array using start date and end date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-enrollment-array-using-start-date-and-end-date/m-p/737489#M229937</link>
      <description>&lt;P&gt;What do expect as &lt;STRONG&gt;final&lt;/STRONG&gt; result?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Apr 2021 04:51:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-enrollment-array-using-start-date-and-end-date/m-p/737489#M229937</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-04-28T04:51:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an enrollment array using start date and end date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-enrollment-array-using-start-date-and-end-date/m-p/737520#M229947</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/372151"&gt;@rdum96&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I'm trying to get a total count for each month. I'm new to this so I'm prolly not thinking the right way. Would appreciate your help&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Could you please state clearly the desired output? Could you please give a realistic example of the input data set (not just two records) that covers the real-world examples that might occur in your data, and the output from that example data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Again, arrays are not the way to get total counts by month.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Apr 2021 09:53:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-enrollment-array-using-start-date-and-end-date/m-p/737520#M229947</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-28T09:53:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an enrollment array using start date and end date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-enrollment-array-using-start-date-and-end-date/m-p/737521#M229948</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/372151"&gt;@rdum96&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;So I would need to include people who joined somewhere in the middle of the year or left in the middle too. I think this would include only people enrolled during the entire spell?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't know what this means, or how it relates to the data you have already provided. Please provide example data that covers the real world situations that you are likely to have, and the desired output from this data.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Apr 2021 09:54:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-enrollment-array-using-start-date-and-end-date/m-p/737521#M229948</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-28T09:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an enrollment array using start date and end date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-enrollment-array-using-start-date-and-end-date/m-p/737527#M229949</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/372151"&gt;@rdum96&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I'm trying to get a total count for each month. I'm new to this so I'm prolly not thinking the right way. Would appreciate your help&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's why you want a long dataset (Maxim 19):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
month = start_date;
format month yymmd7.;
do while (month le end_date);
  output;
  month = intnx('month',month,1,'s');
end;
keep id month;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;From that, it is now easy to get a count of enrolled ID's for a given time period:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table enrolled as
  select
    month,
    count(id) as count
  from want
  where '01jan2020'd le month le '01feb2021'd
  group by month
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=want;
where '01jan2020'd le month le '01feb2021'd;
tables month / nopercent nocum out=enrolled;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Apr 2021 10:09:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-enrollment-array-using-start-date-and-end-date/m-p/737527#M229949</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-28T10:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an enrollment array using start date and end date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-enrollment-array-using-start-date-and-end-date/m-p/737562#M229958</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID         Start_date : ddmmyy10.           end_date : ddmmyy10.;
format  Start_date     end_date ddmmyy10.;
cards;
011      1/1/1996               5/3/2020
003      2/1/2020               12/1/2020
;
data want;
 set have;
 array x{*} Jan2020 Feb2020 Mar2020 Apr2020;

do j=1 to dim(x);
  x{j}=0;
 end;

do i= Start_date to    end_date;
 do j=1 to dim(x);
   if upcase(put(i,monyy7.))=upcase(vname(x{j})) then x{j}=1;
 end;
end;
drop i j;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Apr 2021 12:59:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-an-enrollment-array-using-start-date-and-end-date/m-p/737562#M229958</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-04-28T12:59:48Z</dc:date>
    </item>
  </channel>
</rss>

