DATA Step, Macro, Functions and more

How to insert subtotal and total in dataset

Reply
Occasional Contributor
Posts: 8

How to insert subtotal and total in dataset

[ Edited ]

In a dataset containing sales data with three different products on daily basis.

 

 

I want to calculate sales subtotal for each of the product grand total.

 

Looking for SAS code.

Super User
Super User
Posts: 7,401

Re: How to insert subtotal and total in dataset

Follow the guidance below the Post button - post example test data in the form of a datastep, use the {i} button above the post area to post code to retain formatting.  Show what you want out at the end.  Show logs/code you have done and where you are having diccifulties.  Avoid writing in bold an mixed colors.  

To do subtotals, you have several options, proc means, summary, proc sql sum() group by, datastep retain count variable.  They are each useful in different scenarios.

Finally this a Q&A forum not a contract work request page.

Super User
Posts: 5,082

Re: How to insert subtotal and total in dataset

Examine the data set that comes out of this:

 

proc summary data=have;

class product;

var amount;

output out=stats sum=;

run;

 

It will contain what you ask, but you will need to study a little to figure out the various pieces of the output.  If you want to use SAS, this is a tool you must master.

Super User
Posts: 5,256

Re: How to insert subtotal and total in dataset

Please don't store totals in a data set unless its only use will be for 1-1 report display.
Procedures like TABULATE and REPORT has this OOTB.
Data never sleeps
Ask a Question
Discussion stats
  • 3 replies
  • 130 views
  • 3 likes
  • 4 in conversation