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,

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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?


 

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

With minimal information to go on:

data want;
  set have;
  length period $20;
  period=ifc(day in (6,0),"Weekend","Weekday");
run;

 

matt23
Quartz | Level 8

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?

ballardw
Super User

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

Reeza
Super User

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?


 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 1164 views
  • 6 likes
  • 4 in conversation