<?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 Hash table calculations? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Hash-table-calculations/m-p/265645#M52264</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have a table that tracks Users and LoginDates&lt;/P&gt;
&lt;P&gt;UserID LoginDate&lt;/P&gt;
&lt;P&gt;1 '02Jan2015'&lt;/P&gt;
&lt;P&gt;1 '03Jan2015'&lt;/P&gt;
&lt;P&gt;1 '22Jan2015'&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to create a table where I evaluate at each month end reporting period to calculate the activity of a user into the following categories:&lt;/P&gt;
&lt;P&gt;Daily User: 15+ days in a month&lt;/P&gt;
&lt;P&gt;Else Weekly User: &amp;lt;15days in a month and once every calendar week&lt;/P&gt;
&lt;P&gt;Else Monthly User: atleast once in current month&lt;/P&gt;
&lt;P&gt;Else Quarterly User: atleast once&amp;nbsp;in last 3 months&lt;/P&gt;
&lt;P&gt;Else Annual User atleast once in last year&lt;/P&gt;
&lt;P&gt;Else Inactive - no activity in 1 year&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because my fact table only capture activity, i'm not sure how to go about evaluating at each month end period to create a table i can use to report on that may look like:&lt;/P&gt;
&lt;P&gt;UserID ReportDate Status&lt;/P&gt;
&lt;P&gt;1 '31Jan2015' Weekly&lt;/P&gt;
&lt;P&gt;1 '29Feb2015' Daily&lt;/P&gt;
&lt;P&gt;1 '31Mar2014' Monthly&lt;/P&gt;
&lt;P&gt;etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Every month the total should reflect my entire User base at that period of time (it is additive so every month it will greater than the previous.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance for your help!&lt;/P&gt;</description>
    <pubDate>Fri, 22 Apr 2016 13:58:33 GMT</pubDate>
    <dc:creator>DangIT</dc:creator>
    <dc:date>2016-04-22T13:58:33Z</dc:date>
    <item>
      <title>Hash table calculations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-table-calculations/m-p/265645#M52264</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have a table that tracks Users and LoginDates&lt;/P&gt;
&lt;P&gt;UserID LoginDate&lt;/P&gt;
&lt;P&gt;1 '02Jan2015'&lt;/P&gt;
&lt;P&gt;1 '03Jan2015'&lt;/P&gt;
&lt;P&gt;1 '22Jan2015'&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to create a table where I evaluate at each month end reporting period to calculate the activity of a user into the following categories:&lt;/P&gt;
&lt;P&gt;Daily User: 15+ days in a month&lt;/P&gt;
&lt;P&gt;Else Weekly User: &amp;lt;15days in a month and once every calendar week&lt;/P&gt;
&lt;P&gt;Else Monthly User: atleast once in current month&lt;/P&gt;
&lt;P&gt;Else Quarterly User: atleast once&amp;nbsp;in last 3 months&lt;/P&gt;
&lt;P&gt;Else Annual User atleast once in last year&lt;/P&gt;
&lt;P&gt;Else Inactive - no activity in 1 year&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because my fact table only capture activity, i'm not sure how to go about evaluating at each month end period to create a table i can use to report on that may look like:&lt;/P&gt;
&lt;P&gt;UserID ReportDate Status&lt;/P&gt;
&lt;P&gt;1 '31Jan2015' Weekly&lt;/P&gt;
&lt;P&gt;1 '29Feb2015' Daily&lt;/P&gt;
&lt;P&gt;1 '31Mar2014' Monthly&lt;/P&gt;
&lt;P&gt;etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Every month the total should reflect my entire User base at that period of time (it is additive so every month it will greater than the previous.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance for your help!&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2016 13:58:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-table-calculations/m-p/265645#M52264</guid>
      <dc:creator>DangIT</dc:creator>
      <dc:date>2016-04-22T13:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: Hash table calculations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-table-calculations/m-p/265651#M52265</link>
      <description>&lt;P&gt;Should be a simple SQL step, and use intnx() to get the date intervals e.g. (this should start you off, without test data (in the form of a datastep) and the fact that I am leaving now prevents further code):&lt;/P&gt;
&lt;PRE&gt;data have;
  userid=1; logindate="02jan2015"d; output;
  userid=1; logindate="03jan2015"d; output;
  userid=1; logindate="22jan2015"d; output;
run;

proc sql;
  create table TMP as
  select  USERID,
          max(LOGINDATE) as LAST_LOGIN format=date9.,
          case  when CALCULATED LAST_LOGIN &amp;lt; intnx("year",today(),-1) then "Over 1 year"
                when intnx("day",today(),-15) &amp;lt;= CALCULATED LAST_LOGIN &amp;lt;= today() then "Within 15 days"
                ...  /* for current month, last 3 months etc. */
                when intnx("year",today(),-1) &amp;lt;= CALCULATED LAST_LOGIN &amp;lt;= today() then "Within 1 year"
                else "" end as RESULT
  from    HAVE
  group by USERID;
quit;
&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Apr 2016 14:23:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-table-calculations/m-p/265651#M52265</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-22T14:23:29Z</dc:date>
    </item>
    <item>
      <title>Re: Hash table calculations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-table-calculations/m-p/265662#M52269</link>
      <description>Thank you for your quick response.&lt;BR /&gt;This solution will give me values where there is activity in the fact table. I would like to evaluate and output a record for a user even if they do not have activity in the month of evaluation.</description>
      <pubDate>Fri, 22 Apr 2016 15:09:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-table-calculations/m-p/265662#M52269</guid>
      <dc:creator>DangIT</dc:creator>
      <dc:date>2016-04-22T15:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: Hash table calculations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-table-calculations/m-p/265685#M52278</link>
      <description>&lt;P&gt;Create a list of the values you want then join the other onto that:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table TMP as
  select  *
  from    (select distinct USERID from HAVE) A
  left join (
  select  USERID,
          max(LOGINDATE) as LAST_LOGIN format=date9.,
          case  when CALCULATED LAST_LOGIN &amp;lt; intnx("year",today(),-1) then "Over 1 year"
                when intnx("day",today(),-15) &amp;lt;= CALCULATED LAST_LOGIN &amp;lt;= today() then "Within 15 days"
                ...  /* for current month, last 3 months etc. */
                when intnx("year",today(),-1) &amp;lt;= CALCULATED LAST_LOGIN &amp;lt;= today() then "Within 1 year"
                else "" end as RESULT
  from    HAVE
  group by USERID) B
  on      A.USERID=B.USERID;
quit;&lt;/PRE&gt;
&lt;P&gt;Or you could do it in a datastep:&lt;/P&gt;
&lt;PRE&gt;proc sort data=have out=want;
  by userid descending logindate;  /* Note the descending keyword - this puts latest first */
run;

data want;
  set want;
  by userid;
  if first.userid then do;
    if intnx('year',today(),-1) &amp;lt; logindate then result="A year before";
    if intnx('day',....
    ...
    output;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;This will output only the first record for each userid, and the if's will populate the flag. &amp;nbsp;Probably more resource friendly doing it in the datastep if you have lots of data.&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;
&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>Fri, 22 Apr 2016 16:28:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-table-calculations/m-p/265685#M52278</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-22T16:28:34Z</dc:date>
    </item>
  </channel>
</rss>

