Hi,
My data looks something like this:
input load day month datalines: 12345 0 12 12456 1 12 12222 2 12 14532 3 12 15111 4 12 15222 5 12 15333 6 12 ;
and so on. I want to group into weekdays and weekends where day (6,0) = weekend and (1,2,3,4,5) = weekday
and then make a scatterplot to compare weekend load vs weekday load
Close.
You create the weekday variable as indicated by a previous poster. That value is stored in the variable PERIOD. Then you would put that variable name in the GROUP = section.
data have;
input load day month temperature;
weekday_end = ifc(day in (0,6), 'Weekend', 'Weekday', .);
datalines;
12345 0 12 35
12456 1 12 33
12222 2 12 32
14532 3 12 31
15111 4 12 25
15222 5 12 24
15333 6 12 33
;
proc sgplot data=have;
title 'Weekend Load vs Weekday Load';
scatter x=Temperature y=Load / group= weekday_end;
run;
@matt23 wrote:
Sorry this was a bad data example. Here's better representation
input load day month temperature datalines: 12345 0 12 35 12456 1 12 33 12222 2 12 32 14532 3 12 31 15111 4 12 25 15222 5 12 24 15333 6 12 33 ;And now I want to do a grouped scatter plot:
proc sgplot data=dataname; title 'Weekend Load vs Weekday Load'; scatter x=Temperature y=Load / group=?? Weekend or Wekkday ??; run;how would I edit my code so it counts day 0 and 6 as weekend and the rest as weekdays?
With minimal information to go on:
data want; set have; length period $20; period=ifc(day in (6,0),"Weekend","Weekday"); run;
Sorry this was a bad data example. Here's better representation
input load day month temperature datalines: 12345 0 12 35 12456 1 12 33 12222 2 12 32 14532 3 12 31 15111 4 12 25 15222 5 12 24 15333 6 12 33 ;
And now I want to do a grouped scatter plot:
proc sgplot data=dataname; title 'Weekend Load vs Weekday Load'; scatter x=Temperature y=Load / group=?? Weekend or Wekkday ??; run;
how would I edit my code so it counts day 0 and 6 as weekend and the rest as weekdays?
@matt23 wrote:
Sorry this was a bad data example. Here's better representation
input load day month temperature datalines: 12345 0 12 35 12456 1 12 33 12222 2 12 32 14532 3 12 31 15111 4 12 25 15222 5 12 24 15333 6 12 33 ;And now I want to do a grouped scatter plot:
proc sgplot data=dataname; title 'Weekend Load vs Weekday Load'; scatter x=Temperature y=Load / group=?? Weekend or Wekkday ??; run;how would I edit my code so it counts day 0 and 6 as weekend and the rest as weekdays?
Use @RW9's code to add period (or other likely variable name) and use that variable with the group= option.
Or create a custom format, apply that format to the day variable and use day as the group variable.
Close.
You create the weekday variable as indicated by a previous poster. That value is stored in the variable PERIOD. Then you would put that variable name in the GROUP = section.
data have;
input load day month temperature;
weekday_end = ifc(day in (0,6), 'Weekend', 'Weekday', .);
datalines;
12345 0 12 35
12456 1 12 33
12222 2 12 32
14532 3 12 31
15111 4 12 25
15222 5 12 24
15333 6 12 33
;
proc sgplot data=have;
title 'Weekend Load vs Weekday Load';
scatter x=Temperature y=Load / group= weekday_end;
run;
@matt23 wrote:
Sorry this was a bad data example. Here's better representation
input load day month temperature datalines: 12345 0 12 35 12456 1 12 33 12222 2 12 32 14532 3 12 31 15111 4 12 25 15222 5 12 24 15333 6 12 33 ;And now I want to do a grouped scatter plot:
proc sgplot data=dataname; title 'Weekend Load vs Weekday Load'; scatter x=Temperature y=Load / group=?? Weekend or Wekkday ??; run;how would I edit my code so it counts day 0 and 6 as weekend and the rest as weekdays?
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.