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

 

Hello,

 

I got the following output after performing a frequency procedure and transposing by month.

Later, i want to create a grand_total on the resultant dataset like shown.

is it acheived by using an array?

 

 

Month      Jan    Feb  mar  apr  may  jun   jul   grand_total

Male         6          4    3      8       8     0     .        29  

Female    4           4    7      7       0     .      .        22

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Either use a reporting procedure from the start or calculate sum manually, but an array declaration isn't useful in this situation unless you're going to use it more than once or if you need some dynamic summation.  

 

You can use variable lists without explicitly declaring an array. 

 

Grand_total = sum (of JAN--JUL);

Grand_total = sum(of month1-month7);

View solution in original post

4 REPLIES 4
ChrisBrooks
Ammonite | Level 13

No need for arrays just use the sum function e.g.

 

grand_total=sum(jan, feb, mar, apr, may, jun, jul);

Reeza
Super User

Either use a reporting procedure from the start or calculate sum manually, but an array declaration isn't useful in this situation unless you're going to use it more than once or if you need some dynamic summation.  

 

You can use variable lists without explicitly declaring an array. 

 

Grand_total = sum (of JAN--JUL);

Grand_total = sum(of month1-month7);
robertrao
Quartz | Level 8

Thanks Reeza,

 

The double dashes works fine like shown below in a seperrate data step after the proc transpose.

But putting a single dash inbetween doent work only considers the two months.

 

Grand_total = sum(of Feb2016--Feb2017);

 

Thanks again

 

Reeza
Super User

You can only use single dashes if you have a series of variables with an index, as in the example. And I believe this behaviour changed in 9.3

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 4 replies
  • 1876 views
  • 5 likes
  • 3 in conversation