BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
meetagupta
Fluorite | Level 6

Hi, Below is the dataset that I have.  i want to calculate sum of weekday 1&7(10450+34876) and sum of weekday 2 to 6(5670+78201+..)

How can I do that?

Thanks for all your help

 

weekday      sum

1               10450

2                5670

3                78201

4                8723

5                60981

6                8921

7                34876

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

One way is to create format that will group values as you want.

 

proc format library=work;
value myweekdays
1,7 = '1 7'
2 - 6 = '2 to 6'
;
run;

data have;
 input weekday      sum;
datalines;
1               10450
2                5670
3                78201
4                8723
5                60981
6                8921
7                34876
;
proc means data=have sum;
   class weekday;
   format weekday myweekdays.;
   var sum;
run;

Groups of values created with a format can be used in almost any analysis, graphing or reporting procedure to create the needed groups.

View solution in original post

3 REPLIES 3
ballardw
Super User

One way is to create format that will group values as you want.

 

proc format library=work;
value myweekdays
1,7 = '1 7'
2 - 6 = '2 to 6'
;
run;

data have;
 input weekday      sum;
datalines;
1               10450
2                5670
3                78201
4                8723
5                60981
6                8921
7                34876
;
proc means data=have sum;
   class weekday;
   format weekday myweekdays.;
   var sum;
run;

Groups of values created with a format can be used in almost any analysis, graphing or reporting procedure to create the needed groups.

meetagupta
Fluorite | Level 6

It worked! Thank you.

ChrisNZ
Tourmaline | Level 20

In the actual data:

You only expect 2 numbers at the end?

The first field is not a date?

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1138 views
  • 0 likes
  • 3 in conversation