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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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