<?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: using variables from two different tables in ProcSQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-filter-weekly-price-data/m-p/716992#M221687</link>
    <description>&lt;P&gt;You want to divide ALL variables in table RETURN (including the date value!) by VAR3 from table BONDYIELD, and store the result in a single column? How should that work?&lt;/P&gt;
&lt;P&gt;Such formulas need single variables/columns, you cannot use the asterisk there.&lt;/P&gt;</description>
    <pubDate>Fri, 05 Feb 2021 08:23:41 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-02-05T08:23:41Z</dc:date>
    <item>
      <title>How to filter weekly price data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-filter-weekly-price-data/m-p/716342#M221365</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.monthlystock;
set work.stock;
if date = Intnx('MONTH', date, 0, 'END');
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have managed to use the codes attached to filter 'monthly' price data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jun 2021 06:21:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-filter-weekly-price-data/m-p/716342#M221365</guid>
      <dc:creator>igsteo</dc:creator>
      <dc:date>2021-06-02T06:21:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter weekly price data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-filter-weekly-price-data/m-p/716345#M221368</link>
      <description>&lt;P&gt;Show us your data please.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 08:48:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-filter-weekly-price-data/m-p/716345#M221368</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-03T08:48:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter weekly price data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-filter-weekly-price-data/m-p/716363#M221378</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/361282"&gt;@igsteo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.monthlystock;
set work.stock;
if date = Intnx('MONTH', date, 0, 'END');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The historical data of the stock is&amp;nbsp;2007-11-07 to&amp;nbsp;2021-01-19.&lt;/P&gt;
&lt;P&gt;I have managed to use the codes attached to filter 'monthly' price data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, how do i filter to get weekly price data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please describe what specific period, as in days of the week and such that you are looking for.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 10:56:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-filter-weekly-price-data/m-p/716363#M221378</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-03T10:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter weekly price data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-filter-weekly-price-data/m-p/716728#M221554</link>
      <description>&lt;P&gt;If the last trading day of every week were on a Friday, then you could do something analogous to your code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.monthlystock;
  set work.stock;
  if date = Intnx('WEEK.7', date, 0, 'END');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But not all Fridays are trading days.&amp;nbsp; Instead you might want the last trading day of the week (where "week" is defined as starting on Saturday and ending on Friday, i.e.&amp;nbsp; "week.7" in sas date-interval terms.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you could look for the last trading day such that the next trading is in the next "week.7" period, as in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set stocks;
  by stockid;
  if eod2=0 then set stocks (firstobs=2 keep=date rename=(date=nxt_date)) end=eod2;
  else nxt_date='31dec2030'd;

  if intck('week.7',date,nxt_date)&amp;gt;0 or last.stockid;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This assume data are sorted by stockid/date.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 03:39:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-filter-weekly-price-data/m-p/716728#M221554</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-02-04T03:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter weekly price data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-filter-weekly-price-data/m-p/716749#M221563</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mylib.mnprice;
set mylib.pricedata;
if date = Intnx('MONTH', date, 0, 'END');
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The following are my codes and the output. However, i realise months are missing as you can see january 2016, april 2016 is not included.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My start date is 31DEC2015 to 29DEC2020.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do i include missing months where the date is 28th or 29th?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 08:44:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-filter-weekly-price-data/m-p/716749#M221563</guid>
      <dc:creator>igsteo</dc:creator>
      <dc:date>2021-02-05T08:44:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter weekly price data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-filter-weekly-price-data/m-p/716751#M221565</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data intermediate;
set have;
week = intnx('week',date,0,'e');
run;

proc sql;
create table want as
  select
    date,
    price
  from intermediate
  group by week
  having date = max(date)
;
quit;
    &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will always get you the last date that is present for a given week. A week would only miss if there was not even a single price point within that week.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code is not tested in any way, as no &lt;U&gt;usable&lt;/U&gt; data was provided.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 08:26:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-filter-weekly-price-data/m-p/716751#M221565</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-04T08:26:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter weekly price data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-filter-weekly-price-data/m-p/716941#M221659</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data price;
set pricedata;
if date=intnx('weekday',intnx('month',date,0,'e'),0);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;These are my current codes which works except that two months are still missing i.e. 30th july 2020 and 29th December 2020.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How should i modify the codes such that it reflects these two specific data as well?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;alternative method i was thinking is could i specify that 31st July 2020, 30th and 31st December 2020 is a holiday. Hence, it will be excluded in the codes above for working days of the week?&lt;/P&gt;&lt;P&gt;If so, what are the codes?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 08:44:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-filter-weekly-price-data/m-p/716941#M221659</guid>
      <dc:creator>igsteo</dc:creator>
      <dc:date>2021-02-05T08:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter weekly price data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-filter-weekly-price-data/m-p/716967#M221670</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/361282"&gt;@igsteo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data price;
set pricedata;
if date=intnx('weekday',intnx('month',date,0,'e'),0);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;These are my current codes which works except that two months are still missing i.e. 30th july 2020 and 29th December 2020.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How should i modify the codes such that it reflects these two specific data as well?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;alternative method i was thinking is could i specify that 31st July 2020, 30th and 31st December 2020 is a holiday. Hence, it will be excluded in the codes above for working days of the week?&lt;/P&gt;
&lt;P&gt;If so, what are the codes?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You could do exactly what I showed you in the case of weekly prices, where Fridays are not always trading days.&amp;nbsp; Compare the date in the current record with the data in the upcoming record - getting the interval between them in months (using the INTCK function).&amp;nbsp; If a month-end boundary is crossed between them, then keep the current record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My week-oriented code was:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set stocks;
  by stockid;
  if eod2=0 then set stocks (firstobs=2 keep=date rename=(date=nxt_date)) end=eod2;
  else nxt_date='31dec2030'd;

  if intck('week.7',date,nxt_date)&amp;gt;0 or last.stockid;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For end of month, just change "week.7" to "month", as in (I'll also change the data set names).&amp;nbsp; I've also dropped the "by stockid" since your data rows are apparently not grouped by stockid:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data price;
  set pricedata;
  if eod2=0 then set pricedata (firstobs=2 keep=date rename=(date=nxt_date)) end=eod2;
  else nxt_date='31dec2030'd;

  if intck('month',date,nxt_date)&amp;gt;0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The second SET statement starts out at observation 2, so it is always one obs in advance of the current obs from the first SET, giving you a way to look ahead at the next date.&amp;nbsp; The reason it has an "if eod2=0" clause is because a SET without the IF would end the data step one iteration prematurely, since it starts out at obs 2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 05:31:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-filter-weekly-price-data/m-p/716967#M221670</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-02-05T05:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: using variables from two different tables in ProcSQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-filter-weekly-price-data/m-p/716977#M221676</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table reits_rp as
select a.*, b.date, b.VAR3, a.*/b.VAR3 as reit_rp
from return as a, bondyield as b
where a.date=b.date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;a= picture showing stock returns&lt;/P&gt;&lt;P&gt;b= picture showing bond yield&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As show above my codes using proc sql i would like to form a new table where every stock returns (a) minus yield (b) and by date. However, the log reflects an error in '&lt;CODE class=" language-sas"&gt;a.*/b.VAR3'&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;How do i rectify this?&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 08:45:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-filter-weekly-price-data/m-p/716977#M221676</guid>
      <dc:creator>igsteo</dc:creator>
      <dc:date>2021-02-05T08:45:16Z</dc:date>
    </item>
    <item>
      <title>Re: using variables from two different tables in ProcSQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-filter-weekly-price-data/m-p/716992#M221687</link>
      <description>&lt;P&gt;You want to divide ALL variables in table RETURN (including the date value!) by VAR3 from table BONDYIELD, and store the result in a single column? How should that work?&lt;/P&gt;
&lt;P&gt;Such formulas need single variables/columns, you cannot use the asterisk there.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 08:23:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-filter-weekly-price-data/m-p/716992#M221687</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-05T08:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Single Regression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-filter-weekly-price-data/m-p/716995#M221689</link>
      <description />
      <pubDate>Fri, 05 Feb 2021 08:51:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-filter-weekly-price-data/m-p/716995#M221689</guid>
      <dc:creator>igsteo</dc:creator>
      <dc:date>2021-02-05T08:51:59Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Single Regression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-filter-weekly-price-data/m-p/716997#M221691</link>
      <description>&lt;P&gt;This has nothing to do with the original thread subject, please open a new thread in Statistical Procedures.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 08:49:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-filter-weekly-price-data/m-p/716997#M221691</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-05T08:49:07Z</dc:date>
    </item>
  </channel>
</rss>

