<?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: JOINing Two Panels with Different Time Indices in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/JOINing-Two-Panels-with-Different-Time-Indices/m-p/676671#M204055</link>
    <description>&lt;P&gt;Haven't tested thoroughly, but I thinks this will work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ab(keep=firm time a b);
   if _N_ = 1 then do;
      dcl hash h(dataset : "b", ordered : "a", multidata : "y");
      h.definekey("firm");
      h.definedata("b", "time");
      h.definedone();
   end;

   set a;
   if 0 then set b;
   t = time;

   do rc = h.find() by 0 while (rc = 0 &amp;amp; time &amp;lt;= t);
      _b = b;
      rc = h.find_next();
   end;

   b = _b;
   time = t;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;firm time a   b 
1    1    99  11 
1    2    98  11 
1    4    97  15 
1    5    95  15 
2    1    89  . 
2    3    90  42 
2    4    88  42 
2    5    94  29 &lt;/PRE&gt;</description>
    <pubDate>Fri, 14 Aug 2020 09:59:50 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2020-08-14T09:59:50Z</dc:date>
    <item>
      <title>JOINing Two Panels with Different Time Indices</title>
      <link>https://communities.sas.com/t5/SAS-Programming/JOINing-Two-Panels-with-Different-Time-Indices/m-p/676372#M203927</link>
      <description>&lt;P&gt;I have two variables &lt;EM&gt;a&lt;/EM&gt; and &lt;EM&gt;b&lt;/EM&gt; indexed by &lt;EM&gt;firm&lt;/EM&gt; and &lt;EM&gt;time&lt;/EM&gt;&amp;nbsp;as follows.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input firm time a;
cards;
1 1 99
1 2 98
1 4 97
1 5 95
2 1 89
2 3 90
2 4 88
2 5 94
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to append the following &lt;EM&gt;b&lt;/EM&gt; to the &lt;EM&gt;a&lt;/EM&gt; above—for firm 1 (2), &lt;EM&gt;b&lt;/EM&gt; will be updated at time 1 and 4 (2 and 5).&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
input firm time b;
cards;
1 0.9 11
1 3.1 15
2 1.8 42
2 4.2 29
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I tried to JOIN them using A.TIME=CEIL(B.TIME) but failed because firm 2 has no observation at time 2. In addition, the following way appends no information at time 2 and 5 (3 and 4) for firm 1 (2).&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table ab as select a.firm,a.time,a,b from a left join b on a.firm=b.firm and a.time=ceil(b.time) order by firm,time;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am expecting a slow-moving&amp;nbsp;&lt;EM&gt;b&lt;/EM&gt; in addition to the original &lt;EM&gt;a&lt;/EM&gt; after the JOINing. How can I execute this kind of one-to-many JOINing conveniently?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2020 03:02:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/JOINing-Two-Panels-with-Different-Time-Indices/m-p/676372#M203927</guid>
      <dc:creator>Junyong</dc:creator>
      <dc:date>2020-08-13T03:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: JOINing Two Panels with Different Time Indices</title>
      <link>https://communities.sas.com/t5/SAS-Programming/JOINing-Two-Panels-with-Different-Time-Indices/m-p/676393#M203943</link>
      <description>&lt;P&gt;Thanks for posting data in usable form, unfortunately you forgot to add the expected result to your message, leaving me puzzled whether you want to join (=merge) or append those two tables. From the code it seems you want to merge, but in the text you are talking about appending.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2020 04:49:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/JOINing-Two-Panels-with-Different-Time-Indices/m-p/676393#M203943</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-08-13T04:49:01Z</dc:date>
    </item>
    <item>
      <title>Re: JOINing Two Panels with Different Time Indices</title>
      <link>https://communities.sas.com/t5/SAS-Programming/JOINing-Two-Panels-with-Different-Time-Indices/m-p/676397#M203945</link>
      <description>&lt;P&gt;My apologies. Here I add the results I was expecting.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ab;
input firm time a b;
cards;
1 1 99 11
1 2 98 11
1 4 97 15
1 5 95 15
2 1 89 .
2 3 90 42
2 4 88 42
2 5 94 29
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2020 05:35:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/JOINing-Two-Panels-with-Different-Time-Indices/m-p/676397#M203945</guid>
      <dc:creator>Junyong</dc:creator>
      <dc:date>2020-08-13T05:35:52Z</dc:date>
    </item>
    <item>
      <title>Re: JOINing Two Panels with Different Time Indices</title>
      <link>https://communities.sas.com/t5/SAS-Programming/JOINing-Two-Panels-with-Different-Time-Indices/m-p/676409#M203947</link>
      <description>&lt;P&gt;Sorry, but i don't understand the logic you want implemented to return the first three lines for firm=2.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2020 06:24:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/JOINing-Two-Panels-with-Different-Time-Indices/m-p/676409#M203947</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-08-13T06:24:37Z</dc:date>
    </item>
    <item>
      <title>Re: JOINing Two Panels with Different Time Indices</title>
      <link>https://communities.sas.com/t5/SAS-Programming/JOINing-Two-Panels-with-Different-Time-Indices/m-p/676417#M203951</link>
      <description>&lt;P&gt;&lt;EM&gt;b&lt;/EM&gt; should be missing at the beginning for each firm and will be updated accordingly after each arrival in table &lt;EM&gt;b&lt;/EM&gt;&amp;nbsp;(and continued until the next arrival).&lt;/P&gt;&lt;P&gt;For firm 1, for example, the value of &lt;EM&gt;b&lt;/EM&gt; is revised twice at &lt;EM&gt;time&lt;/EM&gt;=0.9 and 3.1. Therefore, at &lt;EM&gt;time&lt;/EM&gt;=1 and 2, the value of &lt;EM&gt;b&lt;/EM&gt; is 11, and at &lt;EM&gt;time&lt;/EM&gt;=4 and 5, the value of &lt;EM&gt;b&lt;/EM&gt; is 15 since the new value arrived at &lt;EM&gt;time&lt;/EM&gt;=3.1. For firm 2, similarly, the value of &lt;EM&gt;b&lt;/EM&gt; is missing before &lt;EM&gt;time&lt;/EM&gt;=1.8. The value of &lt;EM&gt;b&lt;/EM&gt; becomes 42 at &lt;EM&gt;time&lt;/EM&gt;=3 and 4. And finally, it becomes 29 at &lt;EM&gt;time&lt;/EM&gt;=5 because of the update at &lt;EM&gt;time&lt;/EM&gt;=4.2.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2020 07:22:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/JOINing-Two-Panels-with-Different-Time-Indices/m-p/676417#M203951</guid>
      <dc:creator>Junyong</dc:creator>
      <dc:date>2020-08-13T07:22:07Z</dc:date>
    </item>
    <item>
      <title>Re: JOINing Two Panels with Different Time Indices</title>
      <link>https://communities.sas.com/t5/SAS-Programming/JOINing-Two-Panels-with-Different-Time-Indices/m-p/676433#M203955</link>
      <description>&lt;P&gt;Have look at:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set aaaa;
   by firm;

   if first.firm then do;
      b_value = .;
   end;

   do _p = 1 to _count;
      set bbbb(rename= (firm = b_firm time = b_time)) point=_p nobs=_count;
      
      if firm = b_firm and time &amp;gt;= b_time then do;
         b_value = b;
      end;
   end;

   b = b_value;

   drop b_: _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Performance will be disgusting, but could be optimized, maybe &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt; has an idea how point= could be avoided.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2020 09:21:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/JOINing-Two-Panels-with-Different-Time-Indices/m-p/676433#M203955</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-08-13T09:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: JOINing Two Panels with Different Time Indices</title>
      <link>https://communities.sas.com/t5/SAS-Programming/JOINing-Two-Panels-with-Different-Time-Indices/m-p/676671#M204055</link>
      <description>&lt;P&gt;Haven't tested thoroughly, but I thinks this will work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ab(keep=firm time a b);
   if _N_ = 1 then do;
      dcl hash h(dataset : "b", ordered : "a", multidata : "y");
      h.definekey("firm");
      h.definedata("b", "time");
      h.definedone();
   end;

   set a;
   if 0 then set b;
   t = time;

   do rc = h.find() by 0 while (rc = 0 &amp;amp; time &amp;lt;= t);
      _b = b;
      rc = h.find_next();
   end;

   b = _b;
   time = t;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;firm time a   b 
1    1    99  11 
1    2    98  11 
1    4    97  15 
1    5    95  15 
2    1    89  . 
2    3    90  42 
2    4    88  42 
2    5    94  29 &lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Aug 2020 09:59:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/JOINing-Two-Panels-with-Different-Time-Indices/m-p/676671#M204055</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-08-14T09:59:50Z</dc:date>
    </item>
  </channel>
</rss>

