<?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: Row level regression in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Row-level-regression/m-p/671107#M32073</link>
    <description>&lt;P&gt;Hi, the intervals are (1,3,4,5) as in the column names. Here is how it is done in R:&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/21783871/calculating-a-linear-trend-line-for-every-row-of-a-table-in-r" target="_blank"&gt;https://stackoverflow.com/questions/21783871/calculating-a-linear-trend-line-for-every-row-of-a-table-in-r&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The exception is: I have 4 points, the days are not (1,2,3) but (1,3,4,5), and I only care about the slope. Does that make sense? Thank you.&lt;/P&gt;</description>
    <pubDate>Tue, 21 Jul 2020 16:35:25 GMT</pubDate>
    <dc:creator>asasha</dc:creator>
    <dc:date>2020-07-21T16:35:25Z</dc:date>
    <item>
      <title>Row level regression</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Row-level-regression/m-p/671094#M32068</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to do a linear regression on every row and attach the slope as a new column: I have four measurements with unequal intervals, and I need to see the trend. How can I do this in SAS? My desired columns are as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;time_1 time_3 time_4 time_5 calculated_slope&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2020 16:18:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Row-level-regression/m-p/671094#M32068</guid>
      <dc:creator>asasha</dc:creator>
      <dc:date>2020-07-21T16:18:21Z</dc:date>
    </item>
    <item>
      <title>Re: Row level regression</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Row-level-regression/m-p/671102#M32070</link>
      <description>&lt;P&gt;"Slope" implies a change in y as x changes. You don't show any y value(s), or X values; one is missing.&lt;/P&gt;
&lt;P&gt;If you values shown are the measurement at the given time then we need to know what the actual intervals are, especially since you say the intervals are unequal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2020 16:26:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Row-level-regression/m-p/671102#M32070</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-07-21T16:26:33Z</dc:date>
    </item>
    <item>
      <title>Re: Row level regression</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Row-level-regression/m-p/671103#M32071</link>
      <description>&lt;P&gt;Please show an example of inputs.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2020 16:27:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Row-level-regression/m-p/671103#M32071</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-07-21T16:27:25Z</dc:date>
    </item>
    <item>
      <title>Re: Row level regression</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Row-level-regression/m-p/671104#M32072</link>
      <description>&lt;P&gt;You can convert the regression formula to be functions of the variables, for example in a linear regression part of the formula for slope involves a sum of squares, you could use the USS() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you can transpose the data so that each row is now a column of four numbers; and of course there needs to also be a column of the x values; and then run PROC REG with a BY statement.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2020 16:29:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Row-level-regression/m-p/671104#M32072</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-07-21T16:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: Row level regression</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Row-level-regression/m-p/671107#M32073</link>
      <description>&lt;P&gt;Hi, the intervals are (1,3,4,5) as in the column names. Here is how it is done in R:&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/21783871/calculating-a-linear-trend-line-for-every-row-of-a-table-in-r" target="_blank"&gt;https://stackoverflow.com/questions/21783871/calculating-a-linear-trend-line-for-every-row-of-a-table-in-r&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The exception is: I have 4 points, the days are not (1,2,3) but (1,3,4,5), and I only care about the slope. Does that make sense? Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2020 16:35:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Row-level-regression/m-p/671107#M32073</guid>
      <dc:creator>asasha</dc:creator>
      <dc:date>2020-07-21T16:35:25Z</dc:date>
    </item>
    <item>
      <title>Re: Row level regression</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Row-level-regression/m-p/671109#M32074</link>
      <description>&lt;P&gt;This is what I want:&lt;/P&gt;&lt;PRE class="lang-r prettyprint prettyprinted"&gt;&lt;CODE&gt;&lt;SPAN class="com"&gt;time1 time3 time4 time5        slope&lt;/SPAN&gt;
&lt;SPAN class="com"&gt;    1     2     3     4      0.00000&lt;/SPAN&gt;
&lt;SPAN class="com"&gt;    3     2     1     1      4.00000&lt;/SPAN&gt;
&lt;SPAN class="com"&gt;    1     1     5     1     -1.66667&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The slope variable is not currently in the data. The example above does not show correct slopes. Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2020 16:40:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Row-level-regression/m-p/671109#M32074</guid>
      <dc:creator>asasha</dc:creator>
      <dc:date>2020-07-21T16:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: Row level regression</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Row-level-regression/m-p/671120#M32075</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/338636"&gt;@asasha&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi, the intervals are (1,3,4,5) as in the column names. Here is how it is done in R:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/21783871/calculating-a-linear-trend-line-for-every-row-of-a-table-in-r" target="_blank" rel="noopener"&gt;https://stackoverflow.com/questions/21783871/calculating-a-linear-trend-line-for-every-row-of-a-table-in-r&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The exception is: I have 4 points, the days are not (1,2,3) but (1,3,4,5), and I only care about the slope. Does that make sense? Thank you.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The functions in R have no corresponding function in SAS. As I said above, you can convert the formula for slope to a SAS formula, using the USS() function, the SUM() function, and other functions as appropriate.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2020 16:51:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Row-level-regression/m-p/671120#M32075</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-07-21T16:51:58Z</dc:date>
    </item>
    <item>
      <title>Re: Row level regression</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Row-level-regression/m-p/671125#M32076</link>
      <description>&lt;P&gt;Putting variable values in variable names is bad practice. Anyhow, here is a way to do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id time1 time3 time4 time5;
datalines;
1 1 2 3 4
2 3 2 1 1
;

proc transpose data=have out=temp;
by id;
var time:;
run;

data regr;
set temp;
x = input(compress(_name_,,"kd"), best.);
drop _name_;
run;

proc reg data=regr outest=estm noprint;
by id;
model col1 = x;
run;

data want;
merge have estm(keep=id x rename=x=slope);
by id;
run;

proc print data=want noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;id 	time1 	time3 	time4 	time5 	slope
1 	1 	2 	3 	4 	0.74286
2 	3 	2 	1 	1 	-0.54286&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Jul 2020 16:57:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Row-level-regression/m-p/671125#M32076</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-07-21T16:57:10Z</dc:date>
    </item>
    <item>
      <title>Re: Row level regression</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Row-level-regression/m-p/671127#M32078</link>
      <description>&lt;P&gt;I agree with everyone else that this isn't a good idea. That being said, it can be implemented.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input x1 x3 x4 x5 ;
datalines;
-0.069965723 0.492749371 0.955245597 1.346963522 
;
run;

data slope;
set test;
array ys(4) x1 x3 x4 x5;
array vals(6) (1 3 4 5);
xbar = mean(of vals(*));
ybar = mean(of ys(*));



do i=1 to dim(vals);


num=sum(num, (vals(i)-xbar)*(ys(i)-ybar));
den=sum(den, (vals(i)-xbar)**2);


end;

slope = num/den;
run;

proc transpose data=test out=test2(rename=col1=y);
run;

data test2;
set test2;
x=_n_;
run;

proc reg data=test2;
model y=x;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Regression-type-problem-data-in-a-row/m-p/276735" target="_blank"&gt;https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Regression-type-problem-data-in-a-row/m-p/276735&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/338636"&gt;@asasha&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to do a linear regression on every row and attach the slope as a new column: I have four measurements with unequal intervals, and I need to see the trend. How can I do this in SAS? My desired columns are as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;time_1 time_3 time_4 time_5 calculated_slope&lt;/CODE&gt;&lt;/PRE&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2020 17:10:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Row-level-regression/m-p/671127#M32078</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-21T17:10:22Z</dc:date>
    </item>
    <item>
      <title>Re: Row level regression</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Row-level-regression/m-p/671235#M32083</link>
      <description>&lt;P&gt;I point out that the PROC TRANSPOSE method will handle missing Y values properly. The method of writing your own formula for slope, that I and others have mentioned, will not handle missing Y values properly without additional attention.&lt;/P&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Tue, 21 Jul 2020 22:58:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Row-level-regression/m-p/671235#M32083</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-07-21T22:58:04Z</dc:date>
    </item>
  </channel>
</rss>

