Desktop productivity for business analysts and programmers

Making two groups: Weekends and Weekdays

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 89
Accepted Solution

Making two groups: Weekends and Weekdays

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


Accepted Solutions
Solution
‎06-19-2018 11:06 AM
Super User
Posts: 23,992

Re: Making two groups: Weekends and Weekdays

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


All Replies
Super User
Super User
Posts: 9,829

Re: Making two groups: Weekends and Weekdays

With minimal information to go on:

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

 

Frequent Contributor
Posts: 89

Re: Making two groups: Weekends and Weekdays

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?

Super User
Posts: 13,923

Re: Making two groups: Weekends and 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.

Solution
‎06-19-2018 11:06 AM
Super User
Posts: 23,992

Re: Making two groups: Weekends and Weekdays

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?


 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 253 views
  • 6 likes
  • 4 in conversation