Help using Base SAS procedures

Proc Means Question

Reply
Regular Contributor
Posts: 173

Proc Means Question

Hello,

I am trying to use proc means to find the sum for sales amount for each dept. The problem is each dept couuld be listed more than once with different sales amount. I want to cound all of the 'duplicate' dept because that's how the data come in.

But the report is showing the sum for each 'duplicate' dept. I would like to see one combined sum for all duplicate dept. Can i do this with proc means?

PROC MEANS MAXDEC=2 SUM NOPRINT; BY DEPT; VAR SALEAMT;
OUTPUT OUT=C SUM = SALESUM;
DATA D; SET C;
FILE OUT;
PUT @1 DEPT
@11 SALESUM PD7.2;

Help Please ... Thank you
Super Contributor
Super Contributor
Posts: 3,174

Re: Proc Means Question

From what I understand, you want to "count" (do you mean combine together as one DEPT (DEPT='*DUPS*'; )???

Regardless, I believe you will need to pre-process your data file with a DATA step, as follows:

1) sort SAS member input by DEPT, creating a temp file.
2) use DATA step to input/output the temp file, and use FIRST.DEPT and LAST.DEPT to determine where there are multiples, and do something -- either combine these into a single DEPT value or establish a new "count" variable).
3) sort your temp file in DEPT sequence.
4) Use PROC MEANS, as you have shown in your code.

Scott Barry
SBBWorks, Inc.
Regular Contributor
Posts: 173

Re: Proc Means Question

sbb, thanks for your reply. yes, that was 'count'... sorry
I meant 'include' all duplicate dept so that each dept would show up only once with one total in the report
Ask a Question
Discussion stats
  • 2 replies
  • 98 views
  • 0 likes
  • 2 in conversation