<?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 reference data from another dataset using WHERE statement - calculating cum stock returns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-reference-data-from-another-dataset-using-WHERE-statement/m-p/743189#M232610</link>
    <description>&lt;P&gt;Sounds like you are just asking how to join two tables in SQL.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table cum_returns as
  select
      a.permno
    , exp(sum(log(1+a.ret))) - 1 as cum_return
    , min(a.ret) as minret
    , max(a.ret) as maxret
    , n(a.ret) as n_periods
    , nmiss(a.ret) as n_miss
    , sum(a.ret=.P) as n_dot_p
    , min(a.date) as first_date
    , max(a.date) as last_date
  from returns a
  inner join periods b
     on a.permno=b.permno 
    and a.date between b.TransactionDate and intnx('month',b.transactiondate,6,'s')
  group by a.permno
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 23 May 2021 02:43:46 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-05-23T02:43:46Z</dc:date>
    <item>
      <title>How to reference data from another dataset using WHERE statement - calculating cum stock returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reference-data-from-another-dataset-using-WHERE-statement/m-p/743157#M232596</link>
      <description>&lt;P&gt;Hi everyone.&lt;/P&gt;&lt;P&gt;The code below is to calculate cumulative returns for a security for a given time period.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table returns as
select permno, date, ret
from crsp.dsf (keep=permno date ret)
where permno in ( &lt;STRONG&gt;10068 , 12490&lt;/STRONG&gt; )
order by permno, date
;
create table cum_returns as
select permno , exp(sum(log(1+ret))) - 1 as cum_return
, min(ret) as minret , max(ret) as maxret
, n(ret) as n_periods , nmiss(ret) as n_miss
, sum(ret=.P) as n_dot_p , min(date) as first_date
, max(date) as last_date
from returns
where ('&lt;STRONG&gt;01jan1986'd &amp;lt;= date &amp;lt;= '31dec1986'&lt;/STRONG&gt;d)
group by permno
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code above is calculating cumulative returns for 2 securities, 10068 and 12490 between the first_date and last_date (this is bolded above for clarity).&amp;nbsp;&lt;/P&gt;&lt;P&gt;Right now the code is written so that it calculates the cumulative returns for only these 2 securities between these two dates.&lt;/P&gt;&lt;P&gt;I have a separate dataset that contains a list of securities and dates that I want to calculate the cumulative returns for.&lt;/P&gt;&lt;P&gt;Is there a way to replace the code in the WHERE statement in which I can reference my other dataset?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is an example of the other dataset that has this information.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;TransactionDate      Permnos
1	20061222	54594	
2	20060731	54594	
3	20060328	54594	
4	20060804	54594	
5	20160725	54594	
6	20060403	54594	
7	20070201	65832	
8	20070309	65832&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ideally, I want the transaction date to be the first date and and 6 months the transaction date after will be the last date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be much appreciated.&lt;/P&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 May 2021 18:32:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reference-data-from-another-dataset-using-WHERE-statement/m-p/743157#M232596</guid>
      <dc:creator>Mistletoad</dc:creator>
      <dc:date>2021-05-22T18:32:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to reference data from another dataset using WHERE statement - calculating cum stock returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reference-data-from-another-dataset-using-WHERE-statement/m-p/743189#M232610</link>
      <description>&lt;P&gt;Sounds like you are just asking how to join two tables in SQL.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table cum_returns as
  select
      a.permno
    , exp(sum(log(1+a.ret))) - 1 as cum_return
    , min(a.ret) as minret
    , max(a.ret) as maxret
    , n(a.ret) as n_periods
    , nmiss(a.ret) as n_miss
    , sum(a.ret=.P) as n_dot_p
    , min(a.date) as first_date
    , max(a.date) as last_date
  from returns a
  inner join periods b
     on a.permno=b.permno 
    and a.date between b.TransactionDate and intnx('month',b.transactiondate,6,'s')
  group by a.permno
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 23 May 2021 02:43:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reference-data-from-another-dataset-using-WHERE-statement/m-p/743189#M232610</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-23T02:43:46Z</dc:date>
    </item>
  </channel>
</rss>

