BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
azy
Calcite | Level 5 azy
Calcite | Level 5

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).

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

6 REPLIES 6
stat_sas
Ammonite | Level 13

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;

Reeza
Super User

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).


 

azy
Calcite | Level 5 azy
Calcite | Level 5
Thank you. This worked pretty well.
PaigeMiller
Diamond | Level 26
proc reg data=have (firstobs=4) ;
--
Paige Miller
Reeza
Super User
I stand corrected 😉
azy
Calcite | Level 5 azy
Calcite | Level 5
Thank you, Paige. This worked pretty well too!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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