<?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: Linear Regression with data in the same column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Linear-Regression-with-data-in-the-same-column/m-p/353830#M82640</link>
    <description>&lt;P&gt;Suggestion:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;select * from TWX(rename=(dailyreturns=dailyreturns_TWX))&lt;/PRE&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;select * from GSPC(rename=(dailyreturns=dailyreturns_GSPC))&lt;/PRE&gt;</description>
    <pubDate>Wed, 26 Apr 2017 18:06:37 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2017-04-26T18:06:37Z</dc:date>
    <item>
      <title>Linear Regression with data in the same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Linear-Regression-with-data-in-the-same-column/m-p/353824#M82634</link>
      <description>&lt;P&gt;Hi, I had two .csv files that i imported to SAS. My first work file is titled "TWX", second file is "GSPC". They both have the column "Daily Returns" and have their Ticker column as well (TWX and GSPC ticker names respectively), and I am trying to perform a regression of TWX&amp;nbsp;daily returns against GSPC&amp;nbsp;daily returns. So, I understand that I have to merge the files to perform the regression, so I typed in this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
     create table Portfolio as select
          * from TWX
                 outer union corr
     select * from GSPC
     order by ticker, date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, the Daily Returns from both TWX and GSPC were together in the same column called "Daily Return". They are still grouped by their tickers though, so for eg, TWX daily returns are on top and GSPC daily returns are at the bottom.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So,&lt;/P&gt;&lt;P&gt;1) do i change the way i merge the files so that they are in two different daily return columns? If so, how do i do that?&lt;BR /&gt;2) If i dont have to change the way i merge the files, how do i perform a regression from the same column but TWX against GSPC?&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 18:11:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Linear-Regression-with-data-in-the-same-column/m-p/353824#M82634</guid>
      <dc:creator>mng1</dc:creator>
      <dc:date>2017-04-26T18:11:18Z</dc:date>
    </item>
    <item>
      <title>Re: Linear Regression with data in the same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Linear-Regression-with-data-in-the-same-column/m-p/353830#M82640</link>
      <description>&lt;P&gt;Suggestion:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;select * from TWX(rename=(dailyreturns=dailyreturns_TWX))&lt;/PRE&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;select * from GSPC(rename=(dailyreturns=dailyreturns_GSPC))&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Apr 2017 18:06:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Linear-Regression-with-data-in-the-same-column/m-p/353830#M82640</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-04-26T18:06:37Z</dc:date>
    </item>
    <item>
      <title>Re: Linear Regression with data in the same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Linear-Regression-with-data-in-the-same-column/m-p/353832#M82642</link>
      <description>&lt;P&gt;Can you show some example lines of data from each data set and what the desired merged/combined data would look like for those records?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 18:07:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Linear-Regression-with-data-in-the-same-column/m-p/353832#M82642</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-04-26T18:07:58Z</dc:date>
    </item>
    <item>
      <title>Re: Linear Regression with data in the same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Linear-Regression-with-data-in-the-same-column/m-p/353833#M82643</link>
      <description>&lt;P&gt;Do I replace what I have with your answer?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 18:12:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Linear-Regression-with-data-in-the-same-column/m-p/353833#M82643</guid>
      <dc:creator>mng1</dc:creator>
      <dc:date>2017-04-26T18:12:05Z</dc:date>
    </item>
    <item>
      <title>Re: Linear Regression with data in the same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Linear-Regression-with-data-in-the-same-column/m-p/353851#M82649</link>
      <description>&lt;P&gt;You can only use dates for which both returns exist. So the proper query to prepare your regression is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table Portfolio as 
select
          a.date,
          a.returns as TWX_returns,
	  b.returns as GSPC_returns
from 
	TWX as a inner join
	GSPC as b on a.date=b.date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 19:20:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Linear-Regression-with-data-in-the-same-column/m-p/353851#M82649</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-04-26T19:20:25Z</dc:date>
    </item>
    <item>
      <title>Re: Linear Regression with data in the same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Linear-Regression-with-data-in-the-same-column/m-p/353854#M82651</link>
      <description>What if both files have the same dates? I got the files from Yahoo Finance, where I downloaded their historical data after setting the same time period for both.&lt;BR /&gt;</description>
      <pubDate>Wed, 26 Apr 2017 19:22:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Linear-Regression-with-data-in-the-same-column/m-p/353854#M82651</guid>
      <dc:creator>mng1</dc:creator>
      <dc:date>2017-04-26T19:22:33Z</dc:date>
    </item>
    <item>
      <title>Re: Linear Regression with data in the same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Linear-Regression-with-data-in-the-same-column/m-p/353856#M82652</link>
      <description>&lt;P&gt;Yes, that's what you want: columns date,&amp;nbsp;TWX_returns, and&amp;nbsp;GSPC_returns, where date applies to both TWX and GSPC.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 19:27:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Linear-Regression-with-data-in-the-same-column/m-p/353856#M82652</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-04-26T19:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: Linear Regression with data in the same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Linear-Regression-with-data-in-the-same-column/m-p/353861#M82655</link>
      <description>&lt;P&gt;I have typed in the following, but the Portfolio still isn't created.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql; 
	create table GSPC as select
	Ticker, 
	Date, 
	open,
	high,
	low,
	close,
	volume,
	LagClose, 
		(close - LagClose)/LagClose as return format = percentn8.3 label = 'Daily Return'
	from GSPC;
quit;
proc sql;
	create table Portfolio as select
		a. date,
		a. return as TWX_returns,
		b. return as GSPC_returns,
	from
		TWX as a inner join
		GSPC as b on a.date=b.date;
quit;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Apr 2017 19:36:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Linear-Regression-with-data-in-the-same-column/m-p/353861#M82655</guid>
      <dc:creator>mng1</dc:creator>
      <dc:date>2017-04-26T19:36:07Z</dc:date>
    </item>
    <item>
      <title>Re: Linear Regression with data in the same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Linear-Regression-with-data-in-the-same-column/m-p/353865#M82658</link>
      <description>&lt;P&gt;This is what I have for TWX (excluding the part where i imported the data):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;roc sort data = TWX;
		by date;
	format date worddate20.
			open dollar15.2
			high dollar15.2
			low dollar15.2  
			close dollar15.2
			volume comma15.;
run;

proc sql;
		alter table TWX 
		add Ticker char label = 'Stock Ticker Symbol';
		update TWX
				set Ticker = 'TWX';
quit; 
proc sql; 
	create table TWX as select
		*,
		(monotonic() - min(monotonic()) + 1) AS RowIndex label = 'Trading Day Index' 
	from TWX;
quit; 

proc sql; 
	create table TWX as select
		a.*, 
		b.close as LagClose,
		b.RowIndex as LagIndex
	from TWX as a left join TWX as b
	on a.Ticker = b.Ticker and (a.RowIndex - 1)  = (b.RowIndex); 
quit; 

proc sql; 
	create table TWX as select
	Ticker, 
	Date, 
	open,
	high,
	low,
	close,
	volume,
	LagClose, 
		(close - LagClose)/LagClose as return format = percentn8.3 label = 'Daily Return'
	from TWX;
quit; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And I want my merged table to have 3 columns (Date, TWX Daily Returns, GSPC Daily Returns), so i can perform regression of TWX against GSPC.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 19:39:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Linear-Regression-with-data-in-the-same-column/m-p/353865#M82658</guid>
      <dc:creator>mng1</dc:creator>
      <dc:date>2017-04-26T19:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: Linear Regression with data in the same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Linear-Regression-with-data-in-the-same-column/m-p/353917#M82681</link>
      <description>&lt;P&gt;Hi, the previous code you gave me worked in merging the tables horizontally. However, I couldn't perform a regression. This is what i have.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table Portfolio as select
		a.date,
		a.return as TWX_returns,
		b.return as GSPC_returns
	from
		TWX as a inner join
		GSPC as b on a.date = b.date;
quit;
proc reg data = Portfolio OUTEST = Final;
	model TWX_returns = GSPC_returns;
	BY date;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm having problems with the&amp;nbsp;proc reg part&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 21:46:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Linear-Regression-with-data-in-the-same-column/m-p/353917#M82681</guid>
      <dc:creator>mng1</dc:creator>
      <dc:date>2017-04-26T21:46:39Z</dc:date>
    </item>
    <item>
      <title>Re: Linear Regression with data in the same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Linear-Regression-with-data-in-the-same-column/m-p/353926#M82685</link>
      <description>&lt;P&gt;You are asking for a separate regression for each date. That's likely not what you want. Remove the by date statement.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 22:09:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Linear-Regression-with-data-in-the-same-column/m-p/353926#M82685</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-04-26T22:09:02Z</dc:date>
    </item>
  </channel>
</rss>

