## Regression at different hours

Solved
Frequent Contributor
Posts: 89

# Regression at different hours

[ Edited ]

Hi,

I have this model but I want to make a regression model for each specific hour,

proc reg data=dataname(where=(Month in(6,7,8)));
run;

How can I include where=(Hour in(1)) or where=(Hour in(22)) etc. I tried

(where=(Month in(6,7,8))(Hour in(1)))

but it didn't work

Also what can I do when I only want a model where Temperature is Between 55 and 65?

Accepted Solutions
Solution
‎06-27-2018 10:36 AM
Super User
Posts: 13,913

## Re: Regression at different hours

if you want two or more conditions in a where clause use AND

(where=(Month in(6,7,8) and Hour in(1)) )

same with temperature

and   55 le temperature le 65

And "Didn't work" is awful vague. Since the syntax you show

(where=(Month in(6,7,8))(Hour in(1)))

would have generated at least one error you should post the code from the LOG including the error message(s). Best is to copy from the log and then paste into a code box to maintain the text formatting of the messages.

If I were looking to get separate models for each hour I would sort my data by the hour variable and use BY Hour; instead of having 12 or 24 separate where clauses.

All Replies
Solution
‎06-27-2018 10:36 AM
Super User
Posts: 13,913

## Re: Regression at different hours

if you want two or more conditions in a where clause use AND

(where=(Month in(6,7,8) and Hour in(1)) )

same with temperature

and   55 le temperature le 65

And "Didn't work" is awful vague. Since the syntax you show

(where=(Month in(6,7,8))(Hour in(1)))

would have generated at least one error you should post the code from the LOG including the error message(s). Best is to copy from the log and then paste into a code box to maintain the text formatting of the messages.

If I were looking to get separate models for each hour I would sort my data by the hour variable and use BY Hour; instead of having 12 or 24 separate where clauses.

Frequent Contributor
Posts: 89

## Re: Regression at different hours

Sorry, one more question:

How can I edit my code to make the x axis go from 60-95 in every plot:

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

proc sgplot data=matt (where=(Month in(6,7,8)));
by Hour;
xaxis label="Temperature (degrees F)";
run;
Super User
Posts: 13,913

## Re: Regression at different hours

@matt23 wrote:

Sorry, one more question:

How can I edit my code to make the x axis go from 60-95 in every plot:

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

proc sgplot data=matt (where=(Month in(6,7,8)));
by Hour;
xaxis label="Temperature (degrees F)";
run;

Add a VALUES option to the Xaxis statement. You could either explicitly list the values of interest Values=(60 70 80 95) or use something like values=(60 to 95 by 5) to have a tick mark and value at 60, 65, 70 etc.

Frequent Contributor
Posts: 89

## Re: Regression at different hours

You're the best!
☑ This topic is solved.