<?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: Help with lookups - Proc Sql or Hash? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-with-lookups-Proc-Sql-or-Hash/m-p/254388#M48509</link>
    <description>&lt;P&gt;OK. Looks more clear now. Assuming I understand what do you mean.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data UserTxnTbl;
input UserID FileDate : date9. ProdGroup $;
format FileDate  date9.;
cards; 
1 01Jan2015 A
1 01Feb2015 A
1 01Mar2015 A
2 01Jan2015 A
2 01Feb2015 A
2 01Mar2015 A
run;
 
data UserCohortTbl ;
input UserID Cohort : date9.;
format Cohort date9.;
cards; 
1 01Feb2014 
1 01Mar2015
2 01Feb2014 
2 01Mar2015
;
run;
data want;
 set UserCohortTbl(rename=(Cohort=FileDate) in=ina) UserTxnTbl(in=inb);
 by UserID FileDate;
 retain Cohort;
 if first.UserID then call missing(Cohort);
 if ina then Cohort=FileDate;
 if inb;
 format Cohort date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 04 Mar 2016 01:24:55 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-03-04T01:24:55Z</dc:date>
    <item>
      <title>Help with lookups - Proc Sql or Hash?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-lookups-Proc-Sql-or-Hash/m-p/253950#M48369</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have the following tables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UserTxnTbl&lt;/P&gt;
&lt;P&gt;UserID FileDate ProdGroup&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 01Jan2015 A&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1 01Feb2015 A&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1 01Mar2015 A&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UserCohortTbl - a user can exist in multiple Cohorts dependent on FileDate&lt;/P&gt;
&lt;P&gt;UserID FileDate Cohort&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 01Jan2015 01Feb2014&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1 01Mar2015 &amp;nbsp;01Jun2014&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to create a dataset that adds Cohort to UserTxnTbl where it pulls the Cohort value that is Less Than the FileDate in the UserTxnTbl&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Want&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;UserID &lt;/SPAN&gt;&lt;SPAN&gt;File&lt;/SPAN&gt;&lt;SPAN&gt;Date ProdGroup Cohort&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;1 01Jan2015 A&amp;nbsp;&lt;SPAN&gt;01Feb2014&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1 01Feb2015 A&amp;nbsp;01Feb2014&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1 01Mar2015 A&amp;nbsp;01Jun201&lt;SPAN&gt;4&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2016 20:01:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-lookups-Proc-Sql-or-Hash/m-p/253950#M48369</guid>
      <dc:creator>DangIT</dc:creator>
      <dc:date>2016-03-02T20:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: Help with lookups - Proc Sql or Hash?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-lookups-Proc-Sql-or-Hash/m-p/253986#M48382</link>
      <description>The logic is not clear. Both dates in Cohort are earlier than all file dates in Txn.&lt;BR /&gt;Describe the business requirement and a more thorough example for a better understanding.</description>
      <pubDate>Wed, 02 Mar 2016 21:37:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-lookups-Proc-Sql-or-Hash/m-p/253986#M48382</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-03-02T21:37:08Z</dc:date>
    </item>
    <item>
      <title>Re: Help with lookups - Proc Sql or Hash?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-lookups-Proc-Sql-or-Hash/m-p/253989#M48383</link>
      <description>&lt;P&gt;Also, are the dates SAS date valued numerics displayed with a Date9. format or character values?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2016 21:41:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-lookups-Proc-Sql-or-Hash/m-p/253989#M48383</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-03-02T21:41:33Z</dc:date>
    </item>
    <item>
      <title>Re: Help with lookups - Proc Sql or Hash?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-lookups-Proc-Sql-or-Hash/m-p/254024#M48394</link>
      <description>&lt;P&gt;Yes. It is not clear . what if the tables like the following, what you gonna do ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UserTxnTbl&lt;/P&gt;
&lt;P&gt;UserID FileDate ProdGroup&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 01Jan2015 A&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1 01Feb2015 A&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1 01Mar2015 A&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UserCohortTbl - a user can exist in multiple Cohorts dependent on FileDate&lt;/P&gt;
&lt;P&gt;UserID FileDate Cohort&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 01Jan2015 01Feb2014&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;1 01Feb2014&amp;nbsp;01Mar2015&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1 01Mar2015 &amp;nbsp;01Jun2014&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2016 01:24:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-lookups-Proc-Sql-or-Hash/m-p/254024#M48394</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-03-03T01:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: Help with lookups - Proc Sql or Hash?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-lookups-Proc-Sql-or-Hash/m-p/254156#M48433</link>
      <description>&lt;P&gt;Sorry let me start this again:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UserTxnTbl: A table that captures all transactions of a product group at the beginning of the month for all users starting 01Jan2015 and going forward. If there is no transactions the FileDate will not exist for that month.&lt;/P&gt;
&lt;P&gt;UserID FileDate ProdGroup&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 01Jan2015 A&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1 01Feb2015 A&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1 01Mar2015 A&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UserCohortTbl - A table that has analyzed the history of users and classified them into a Cohort at a point in time. From 01Feb2014 to 01Feb2015 User 1 belonged to Cohort 01Feb2014. In March 2015 they may have changed some sort of behaviour that&amp;nbsp;redefined their cohort going forward.&lt;/P&gt;
&lt;P&gt;UserID Cohort&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 01Feb2014&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1 01Mar2015&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ultimately I am looking to add Cohort to the UserTxnTbl to identify which Cohort the user belonged to at the FileDate period.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Want&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;UserID &lt;/SPAN&gt;&lt;SPAN&gt;File&lt;/SPAN&gt;&lt;SPAN&gt;Date ProdGroup Cohort&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;1 01Jan2015 A&amp;nbsp;&lt;SPAN&gt;01Feb2014&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1 01Feb2015 A&amp;nbsp;01Feb2014&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1 01Mar2015 A&amp;nbsp;01Mar201&lt;SPAN&gt;5&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;Apologies again for the vaugeness in the original post. After typing this out again, i'm thinking Proc Format might work??&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;Thanks again for your help&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2016 14:00:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-lookups-Proc-Sql-or-Hash/m-p/254156#M48433</guid>
      <dc:creator>DangIT</dc:creator>
      <dc:date>2016-03-03T14:00:43Z</dc:date>
    </item>
    <item>
      <title>Re: Help with lookups - Proc Sql or Hash?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-lookups-Proc-Sql-or-Hash/m-p/254388#M48509</link>
      <description>&lt;P&gt;OK. Looks more clear now. Assuming I understand what do you mean.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data UserTxnTbl;
input UserID FileDate : date9. ProdGroup $;
format FileDate  date9.;
cards; 
1 01Jan2015 A
1 01Feb2015 A
1 01Mar2015 A
2 01Jan2015 A
2 01Feb2015 A
2 01Mar2015 A
run;
 
data UserCohortTbl ;
input UserID Cohort : date9.;
format Cohort date9.;
cards; 
1 01Feb2014 
1 01Mar2015
2 01Feb2014 
2 01Mar2015
;
run;
data want;
 set UserCohortTbl(rename=(Cohort=FileDate) in=ina) UserTxnTbl(in=inb);
 by UserID FileDate;
 retain Cohort;
 if first.UserID then call missing(Cohort);
 if ina then Cohort=FileDate;
 if inb;
 format Cohort date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Mar 2016 01:24:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-lookups-Proc-Sql-or-Hash/m-p/254388#M48509</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-03-04T01:24:55Z</dc:date>
    </item>
  </channel>
</rss>

