<?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 create trade date? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-trade-date/m-p/507085#M136033</link>
    <description>Hi Kurt, when I am running the code for some days the date format are not changing. Therefore, I am getting correct and incorrect dates both. Any ways to fix that? Also, I think you mean to format the settlement date first, right?</description>
    <pubDate>Wed, 24 Oct 2018 09:59:00 GMT</pubDate>
    <dc:creator>bd_user_10</dc:creator>
    <dc:date>2018-10-24T09:59:00Z</dc:date>
    <item>
      <title>How to create trade date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-trade-date/m-p/507080#M136030</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have&amp;nbsp;the following settlement dates in my dataset;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;20020514&lt;/P&gt;&lt;P&gt;20020522&lt;/P&gt;&lt;P&gt;20020524&lt;/P&gt;&lt;P&gt;20020527&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to find the trade date which is settlement dates -3 days but has to be working day. How to do that?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone please help? Thanks in advance for your help.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Oct 2018 08:44:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-trade-date/m-p/507080#M136030</guid>
      <dc:creator>bd_user_10</dc:creator>
      <dc:date>2018-10-24T08:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to create trade date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-trade-date/m-p/507082#M136032</link>
      <description>&lt;P&gt;Subtract 3, and then check for Saturday and Sunday:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
format trade_date yymmddd10.;
trade_date = settlement - 3;
do while (weekday(trade_date) in (1,7));
  trade_date = trade_date - 1;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For more complicated calculations, consider to use the holiday() function.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Oct 2018 08:58:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-trade-date/m-p/507082#M136032</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-24T08:58:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to create trade date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-trade-date/m-p/507085#M136033</link>
      <description>Hi Kurt, when I am running the code for some days the date format are not changing. Therefore, I am getting correct and incorrect dates both. Any ways to fix that? Also, I think you mean to format the settlement date first, right?</description>
      <pubDate>Wed, 24 Oct 2018 09:59:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-trade-date/m-p/507085#M136033</guid>
      <dc:creator>bd_user_10</dc:creator>
      <dc:date>2018-10-24T09:59:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to create trade date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-trade-date/m-p/507090#M136035</link>
      <description>&lt;P&gt;Since you did not provide a data step with example data, I had to make up my own. I also assume that date values are always stored as SAS dates.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input settlement :yymmdd8.;
format settlement yymmddd10.;
cards;
20020514
20020522
20020524
20020527
;
run;

data want;
set have;
format trade_date yymmddd10.;
trade_date = settlement - 3;
do while (weekday(trade_date) in (1,7));
  trade_date = trade_date - 1;
end;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;settlement    trade_date

2002-05-14    2002-05-10
2002-05-22    2002-05-17
2002-05-24    2002-05-21
2002-05-27    2002-05-24
&lt;/PRE&gt;
&lt;P&gt;2002-05-14 was a Tuesday, 2002-05-10 a Friday&lt;/P&gt;
&lt;P&gt;2002-05-22 was a Wednesday, so we have to go back one day further&lt;/P&gt;
&lt;P&gt;The next two dates were a Friday and a Monday, so going back just 3 hits another weekday.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Oct 2018 10:26:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-trade-date/m-p/507090#M136035</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-24T10:26:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to create trade date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-trade-date/m-p/507133#M136054</link>
      <description>&lt;P&gt;Are you saying it's ok to have a trade date on a holiday, as long as that holiday is a Mon through Fri?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if by trade, you mean trade on a public stock exchange,&amp;nbsp;there are non-holidays closuers, such as 9/11/2001, a Tuesday.&amp;nbsp; The New York Stock exchange did not open that day, and did not re-open until 9/17.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If either of the above conditions are relevant to your task, you may need to define a calendar using all active trade dates.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Oct 2018 13:35:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-trade-date/m-p/507133#M136054</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-10-24T13:35:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to create trade date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-trade-date/m-p/507384#M136185</link>
      <description>Thank you very much for clarification! It works fine!</description>
      <pubDate>Thu, 25 Oct 2018 02:53:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-trade-date/m-p/507384#M136185</guid>
      <dc:creator>bd_user_10</dc:creator>
      <dc:date>2018-10-25T02:53:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to create trade date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-trade-date/m-p/507390#M136188</link>
      <description>Hi mkeintz, thanks for a very good point! How to define such calendar? Could you please help?</description>
      <pubDate>Thu, 25 Oct 2018 03:12:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-trade-date/m-p/507390#M136188</guid>
      <dc:creator>bd_user_10</dc:creator>
      <dc:date>2018-10-25T03:12:04Z</dc:date>
    </item>
  </channel>
</rss>

