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

Hi, I run this PROC REG to get results for every hour and I get this error and I miss a result for hour 23.

ERROR: Data set WORK.MATT is not sorted in ascending sequence. The current BY group has Hour = 23 and
       the next BY group has Hour = 0.

This is my code:

proc sort data=matt (where=(Month in(6,7,8)));
by Month Hour;
run;

proc reg data=matt (where=(Month in(6,7,8)));
model Load=Temperature;
by Hour;
label Load="Load (MW)" Temperature="Temperature (degrees F)";
title 'Load vs Temperature (Summer)';
run;

Also, I should be getting results for about 900 observation for every hour and only get about 250. What is wrong with my code?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

You switch your BY statements.  Sorting uses BY MONTH HOUR, but regression uses BY HOUR.

 

They need to be the same.  I'm not sure which one should be used, since that depends on the output that you want.  But the BY statement should be the same for both sorting and regression.

View solution in original post

7 REPLIES 7
Reeza
Super User

 

 


@matt23 wrote:

Hi, I run this PROC REG to get results for every hour and I get this error and I miss a result for hour 23.

ERROR: Data set WORK.MATT is not sorted in ascending sequence. The current BY group has Hour = 23 and
       the next BY group has Hour = 0.

This is my code:

proc sort data=matt (where=(Month in(6,7,8)));
by Month Hour;
run;

proc reg data=matt (where=(Month in(6,7,8)));
model Load=Temperature;
by Hour;
label Load="Load (MW)" Temperature="Temperature (degrees F)";
title 'Load vs Temperature (Summer)';
run;

Also, I should be getting results for about 900 observation for every hour and only get about 250. What is wrong with my code?

 


There are only 24 hours so specifying "BY hour;" would give you 24 estimates.

 

It means your BY group isn't really hour, it's probably day and hour. 

 

If you're using HOUR it expects all hour=0 to be the same group which is not what you want.

matt23
Quartz | Level 8
How would I fix this? How would I specify that I want all data from months 6,7,8 and that I want it separately for every hour?
Reeza
Super User

You need to uniquely identify each group that you want somehow. Which variables in your data set uniquely identify the group? If you don't have a  day, what happens if the data is out of order? How can you be sure which hour goes with which day? Relying solely on order is not a good idea.

 

And note that if you only have a single measurement per record (ie per hour/day) then you would get no results.

 


@matt23 wrote:
How would I fix this? How would I specify that I want all data from months 6,7,8 and that I want it separately for every hour?

 

 

matt23
Quartz | Level 8

Should I just do this for every hour then ?

 

proc reg data=matt (where=(Month in(6,7,8)) AND (Hour in(1)));
Astounding
PROC Star

You switch your BY statements.  Sorting uses BY MONTH HOUR, but regression uses BY HOUR.

 

They need to be the same.  I'm not sure which one should be used, since that depends on the output that you want.  But the BY statement should be the same for both sorting and regression.

matt23
Quartz | Level 8
This solved it. Thank you so much !!
Reeza
Super User

I'm sure you know but your data violates the assumptions for linear regression because there's likely serial correlation.

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 7 replies
  • 901 views
  • 2 likes
  • 3 in conversation