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
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.
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.
It worked! Thank you.
In the actual data:
You only expect 2 numbers at the end?
The first field is not a date?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.