<?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 Tabulating: how many people in my dataset are &amp;quot;pending&amp;quot; each Friday of the year in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Tabulating-how-many-people-in-my-dataset-are-quot-pending-quot/m-p/276897#M55526</link>
    <description>&lt;P&gt;Can anyone tell me whether there's an improved way that I could code this in SAS?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Background to my data: my dataset has one row per individual.&lt;/P&gt;&lt;P&gt;For each individual I have their ID, and the date on which they enrolled on a course and the date on which they finished.&lt;/P&gt;&lt;P&gt;Every individual has a JOINDATE, but not every individual has a LEFTDATE.&lt;/P&gt;&lt;P&gt;Each individual can&amp;nbsp;only appear once in the dataset, however&amp;nbsp;they do not leave in the same&amp;nbsp;order in which they joined, e.g. data like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Person1, JOINDATE=01may16 LEFTDATE=30may16&lt;/P&gt;&lt;P&gt;Person2, JOINDATE=02may16 LEFTDATE=.&lt;/P&gt;&lt;P&gt;Person3, JOINDATE=03may16 LEFTDATE=25may16&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create an output table showing for every Friday during the past year, how many people were on the course on that date.&lt;/P&gt;&lt;P&gt;At the moment I have some macro code which creates a variable for every Friday in the year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example for Fri6th June my variable is called PRESENT_06Jun16&lt;/P&gt;&lt;P&gt;I then&amp;nbsp;have set of If-then statement to check whether PRESENT_06Jun16 is true or false for each individual:&lt;/P&gt;&lt;P&gt;e.g. if JOINDATE&amp;nbsp;le '06jun16'd and (LEFTDATE &amp;gt; '06jun16'd OR LEFTDATE=.) then PRESENT_06Jun16=true; else PRESENT_06Jun16=false.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I'm creating 52 extra variables in this dataset, one for every week,&amp;nbsp;which I'm then tabulating. This seems a really long winded way to get the table that I'm after. Can anyone help with an improved&amp;nbsp;method to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know that another way to get the same output would be to calculate the cumulative number of people who had joined up to date X and the cumulative number of people who had left up to date X, and subtracting one from the other would give me the number who must be present on date X - but I've not found a handy way to do this method in SAS either. (I want to create my output in SAS and not have to export two tables to Excel and subtract one table&amp;nbsp;from the other in there if you see what I mean.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any help! (I'm using SAS v9.3)&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>Mon, 13 Jun 2016 12:06:44 GMT</pubDate>
    <dc:creator>H_C</dc:creator>
    <dc:date>2016-06-13T12:06:44Z</dc:date>
    <item>
      <title>Tabulating: how many people in my dataset are "pending" each Friday of the year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Tabulating-how-many-people-in-my-dataset-are-quot-pending-quot/m-p/276897#M55526</link>
      <description>&lt;P&gt;Can anyone tell me whether there's an improved way that I could code this in SAS?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Background to my data: my dataset has one row per individual.&lt;/P&gt;&lt;P&gt;For each individual I have their ID, and the date on which they enrolled on a course and the date on which they finished.&lt;/P&gt;&lt;P&gt;Every individual has a JOINDATE, but not every individual has a LEFTDATE.&lt;/P&gt;&lt;P&gt;Each individual can&amp;nbsp;only appear once in the dataset, however&amp;nbsp;they do not leave in the same&amp;nbsp;order in which they joined, e.g. data like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Person1, JOINDATE=01may16 LEFTDATE=30may16&lt;/P&gt;&lt;P&gt;Person2, JOINDATE=02may16 LEFTDATE=.&lt;/P&gt;&lt;P&gt;Person3, JOINDATE=03may16 LEFTDATE=25may16&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create an output table showing for every Friday during the past year, how many people were on the course on that date.&lt;/P&gt;&lt;P&gt;At the moment I have some macro code which creates a variable for every Friday in the year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example for Fri6th June my variable is called PRESENT_06Jun16&lt;/P&gt;&lt;P&gt;I then&amp;nbsp;have set of If-then statement to check whether PRESENT_06Jun16 is true or false for each individual:&lt;/P&gt;&lt;P&gt;e.g. if JOINDATE&amp;nbsp;le '06jun16'd and (LEFTDATE &amp;gt; '06jun16'd OR LEFTDATE=.) then PRESENT_06Jun16=true; else PRESENT_06Jun16=false.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I'm creating 52 extra variables in this dataset, one for every week,&amp;nbsp;which I'm then tabulating. This seems a really long winded way to get the table that I'm after. Can anyone help with an improved&amp;nbsp;method to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know that another way to get the same output would be to calculate the cumulative number of people who had joined up to date X and the cumulative number of people who had left up to date X, and subtracting one from the other would give me the number who must be present on date X - but I've not found a handy way to do this method in SAS either. (I want to create my output in SAS and not have to export two tables to Excel and subtract one table&amp;nbsp;from the other in there if you see what I mean.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any help! (I'm using SAS v9.3)&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>Mon, 13 Jun 2016 12:06:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Tabulating-how-many-people-in-my-dataset-are-quot-pending-quot/m-p/276897#M55526</guid>
      <dc:creator>H_C</dc:creator>
      <dc:date>2016-06-13T12:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: Tabulating: how many people in my dataset are "pending" each Friday of the year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Tabulating-how-many-people-in-my-dataset-are-quot-pending-quot/m-p/276902#M55528</link>
      <description>&lt;P&gt;As a suggestion, to get a good response to your questions, post test data, in the form of a datastep, and what the output should look like. &amp;nbsp;I have made several assumptions in the code I present below. &amp;nbsp;It basically creates a dataset with a weekly date, then merges your data onto that, and sums up by the weekly date:&lt;/P&gt;
&lt;PRE&gt;data have;
  Person=1; JOINDATE="01may2016"d; LEFTDATE="30may2016"d; output;
  Person=2; JOINDATE="02may2016"d; LEFTDATE=.; output;
  Person=3; JOINDATE="03may2016"d; LEFTDATE="25may2016"d; output;
run;

data have2 (drop=i);
  do i=0 to (51*7) by 7;
    date="06Jun2016"d + i;
    output;
  end;
  format date date9.;
run;

proc sql;
  create table WANT as
  select  DATE,
          count(PERSON) as RESULT
  from    (
            select  A.DATE,
                    B.PERSON
            from    HAVE2 A
            left join HAVE B
            on      B.JOINDATE &amp;lt;= A.DATE &amp;lt;= max(today(),B.LEFTDATE)
          )
  group by DATE;
quit;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Jun 2016 12:24:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Tabulating-how-many-people-in-my-dataset-are-quot-pending-quot/m-p/276902#M55528</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-06-13T12:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: Tabulating: how many people in my dataset are "pending" each Friday of the year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Tabulating-how-many-people-in-my-dataset-are-quot-pending-quot/m-p/276929#M55537</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;Very helpful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jun 2016 13:36:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Tabulating-how-many-people-in-my-dataset-are-quot-pending-quot/m-p/276929#M55537</guid>
      <dc:creator>H_C</dc:creator>
      <dc:date>2016-06-13T13:36:56Z</dc:date>
    </item>
  </channel>
</rss>

