Sorry for bad explanation but here's what I have:
I want a dataset with SLOPES for every hour. Now, I run this code:
proc reg data=have outest=outdata NOPRINT; where Month in (3,4,5); where also Weekday in (1,2,3,4,5); model Load=Temperature DewPoint; by Hour; run; proc reg data=have outest=outdata NOPRINT; where Month in (3,4,5); where also Weekday in (0,6); model Load=Temperature DewPoint; by Hour; run;
and I get two tables that look similar to this:
Obs | Hour | _MODEL_ | _TYPE_ | _DEPVAR_ | _RMSE_ | Intercept | Temperature | DewPoint | Load |
1 | 0 | MODEL1 | PARMS | Load | 4121.22 | 72068.94 | -440.384 | 328.518 | -1 |
2 | 1 | MODEL1 | PARMS | Load | 3840.58 | 70860.54 | -491.293 | 341.535 | -1 |
3 | 2 | MODEL1 | PARMS | Load | 3619.64 | 70084.57 | -509.326 | 327.479 | -1 |
4 | 3 | MODEL1 | PARMS | Load | 3455.33 | 70209.15 | -550.968 | 338.977 | -1 |
5 | 4 | MODEL1 | PARMS | Load | 3388.95 | 70123.33 | -545.392 | 315.663 | -1 |
6 | 5 | MODEL1 | PARMS | Load | 3348.44 | 71083.93 | -566.492 | 316.459 | -1 |
7 | 6 | MODEL1 | PARMS | Load | 3326.66 | 73121.29 | -581.957 | 307.265 | -1 |
8 | 7 | MODEL1 | PARMS | Load | 3399.56 | 76572.61 | -670.97 | 371.085 | -1 |
9 | 8 | MODEL1 | PARMS | Load | 3491.99 | 76623.23 | -544.325 | 300.572 | -1 |
Now, I copy these two tables (weekend and weekdays) and play with them in EXCEL to make something like this:
Hour | WeekendDew | WeekdayDew |
0 | 328.518 | 234 |
1 | 341.535 | 234 |
2 | 327.479 | 342 |
3 | 338.977 | 234 |
Is there a way to automate this somehow so I don't have to make my own table in EXCEL ?
Send the output to different set and merge them while renaming the variable of interest:
proc reg data=have outest=outdata1 NOPRINT; where Month in (3,4,5); where also Weekday in (1,2,3,4,5); model Load=Temperature DewPoint; by Hour; run; proc reg data=have outest=outdata2 NOPRINT; where Month in (3,4,5); where also Weekday in (0,6); model Load=Temperature DewPoint; by Hour; run; data want; merge outdata1 (rename=(dewpoint=weekdaydew)) outdata2 (rename=(dewpoint=weekenddew)) ; by hour; keep hour weekenddew weekdaydew; run;
I think should work. but without input data it is hard to verify.
Easy peasy!
Create your first dataset as OutWeekDay, and your second as OutWeekEnd.
Then run
proc sql noprint;
create table Combined as
select E.Hour, E.Dewpoint as WeekendDew, D.Dewpoint as WeekdayDew
from OutWeekEnd E join OutWeekDay D on
E.Hour = D.Hour;
quit;
Sure:
proc reg data=have outest=outdataDay NOPRINT;
where Month in (3,4,5);
where also Weekday in (1,2,3,4,5);
model Load=Temperature DewPoint;
by Hour;
run;
proc reg data=have outest=outdataEnd NOPRINT;
where Month in (3,4,5);
where also Weekday in (0,6);
model Load=Temperature DewPoint;
by Hour;
run;
data outDataDew;
merge
outdataDay(rename DewPoint=weekDayDew)
outdataEnd(rename DewPoint=weekEndDew);
by hour;
keep hour weekDayDew weekEndDew;
run;
Send the output to different set and merge them while renaming the variable of interest:
proc reg data=have outest=outdata1 NOPRINT; where Month in (3,4,5); where also Weekday in (1,2,3,4,5); model Load=Temperature DewPoint; by Hour; run; proc reg data=have outest=outdata2 NOPRINT; where Month in (3,4,5); where also Weekday in (0,6); model Load=Temperature DewPoint; by Hour; run; data want; merge outdata1 (rename=(dewpoint=weekdaydew)) outdata2 (rename=(dewpoint=weekenddew)) ; by hour; keep hour weekenddew weekdaydew; run;
I think should work. but without input data it is hard to verify.
If you don't mind a different data structure:
data haveReg;
set have;
if month in (3,4,5);
if weekday in (0,6)
then dayEnd = "WeekEnd";
else dayEnd = "WeekDay";
run;
proc sort data=haveReg; by dayEnd hour; run;
proc reg data=have outest=outdata NOPRINT;
by dayEnd hour;
model Load=Temperature DewPoint;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.