Run Regression using data in only specific rows

Accepted Solution Solved
Reply
New Contributor azy
New Contributor
Posts: 3
Accepted Solution

Run Regression using data in only specific rows

Hi,

 

I am new to the SAS software. Please do help with this relatively easy question.

 

I want to run a regression using data from only specific rows in my file. My data is arranged by date. See a sample of my file below:

 

dateaaggkk
1990-01-02112134
1990-01-04344556
1990-01-0786567
1990-01-0957889
1990-01-116687
1990-01-146667
1990-01-1766667
1990-01-2264451
1990-01-25353445
1990-01-2767865

 

 

I want to run my regression using data starting from the 4th row (1990-01-07).


Accepted Solutions
Solution
3 weeks ago
Super User
Posts: 21,546

Re: Run Regression using data in only specific rows

[ Edited ]

Ideally you would have a rule that is better than after the 4th row, i.e. include all rows where the date is after January 9th, because row numbers aren't included by default which means you need to first create the row numbers. 

 

You can use a WHERE option after the data set name:

 

proc reg data=have (where = (date > '09Jan1990'd)) ;

Or you can add a WHERE clause in the PROC REG statement.

 

proc reg data=have ... ;
WHERE date > '09Jan1990'd;

 


azy wrote:

Hi,

 

I am new to the SAS software. Please do help with this relatively easy question.

 

I want to run a regression using data from only specific rows in my file. My data is arranged by date. See a sample of my file below:

 

date aa gg kk
1990-01-02 11 21 34
1990-01-04 34 45 56
1990-01-07 86 5 67
1990-01-09 5 78 89
1990-01-11 6 6 87
1990-01-14 6 6 67
1990-01-17 66 6 67
1990-01-22 6 44 51
1990-01-25 35 34 45
1990-01-27 67 86 5

 

 

I want to run my regression using data starting from the 4th row (1990-01-07).


 

View solution in original post


All Replies
Trusted Advisor
Posts: 1,263

Re: Run Regression using data in only specific rows

Hi,

 

Something like this? I am using a sample data set and you can try on the same pattern on your data set.

 

data have ;
input var1-var4 ;
n = _n_;
cards;
0.5 1 1.2 0.4
0.9 1 1.5 0.2
0.7 1 1.1 0.3
1 1 1 1
3 1 3 1
4 1 6 7
;
proc reg data=have(where = (n>3));
model var1=var2;
quit;

Solution
3 weeks ago
Super User
Posts: 21,546

Re: Run Regression using data in only specific rows

[ Edited ]

Ideally you would have a rule that is better than after the 4th row, i.e. include all rows where the date is after January 9th, because row numbers aren't included by default which means you need to first create the row numbers. 

 

You can use a WHERE option after the data set name:

 

proc reg data=have (where = (date > '09Jan1990'd)) ;

Or you can add a WHERE clause in the PROC REG statement.

 

proc reg data=have ... ;
WHERE date > '09Jan1990'd;

 


azy wrote:

Hi,

 

I am new to the SAS software. Please do help with this relatively easy question.

 

I want to run a regression using data from only specific rows in my file. My data is arranged by date. See a sample of my file below:

 

date aa gg kk
1990-01-02 11 21 34
1990-01-04 34 45 56
1990-01-07 86 5 67
1990-01-09 5 78 89
1990-01-11 6 6 87
1990-01-14 6 6 67
1990-01-17 66 6 67
1990-01-22 6 44 51
1990-01-25 35 34 45
1990-01-27 67 86 5

 

 

I want to run my regression using data starting from the 4th row (1990-01-07).


 

New Contributor azy
New Contributor
Posts: 3

Re: Run Regression using data in only specific rows

Thank you. This worked pretty well.
Respected Advisor
Posts: 2,173

Re: Run Regression using data in only specific rows

proc reg data=have (firstobs=4) ;
--
Paige Miller
Super User
Posts: 21,546

Re: Run Regression using data in only specific rows

Posted in reply to PaigeMiller
I stand corrected Smiley Wink
New Contributor azy
New Contributor
Posts: 3

Re: Run Regression using data in only specific rows

Posted in reply to PaigeMiller
Thank you, Paige. This worked pretty well too!
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 147 views
  • 2 likes
  • 4 in conversation