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-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!

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.

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
  • 3 replies
  • 439 views
  • 0 likes
  • 3 in conversation