Help using Base SAS procedures

request for column sub totals

Reply
Contributor
Posts: 43

request for column sub totals

Hi,
it may be simple issue but i am doing some where wrong can any one help me
to sort out

i would like to get total notix for each price
data test1;
input price notix;
cards;
8 7
0 1
9 6
10 4
12 101
13.5 2
15 2
16.5 62
18 30
0 2
4.5 1
9 200
14 10
16 75
4.5 1
9 140
14 1
16 52
9 108
14 1
16 25
0 8
9 4
13.5 2
16.5 35
18 669
0 1
9 6
10 4
12 101
13.5 2
15 2
16.5 62

;
run;

proc sort data=test1 out=test2;
by price;
run;

/* i got dataset like

0.00 2
0.00 5
0.00 4
1.00 8
...........
*/


data test2;
set test1;
by price;
retain tot1 tot;
if first.price ne . then do;
tot=price+1;
price+1;
tot1=tot+tot;
end;
if last.price then output;
run;

i would like to see my output as

price nooftix
0.00 19
1.00 25
2.25 38
.
.
.
.
.
Super Contributor
Super Contributor
Posts: 3,174

Re: request for column sub totals

Some additional desk-checking, possibly? Also, I recommend you add some SAS diagnostic commands, like a:

PUTLOG ">DIAG1> I am here: " / _ALL_;

along the way in your DATA step to see what SAS is doing in your program.

You never assign a NOTIX var in your DATA step just prior to OUTPUT. Also, you should check the use of TOT variable.

Maybe consider using a PROC SUMMARY approach, instead of a DATA step?

Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: request for column sub totals

Hello Sams1,

It should be ok now. There are two possible solutions, I think, as proposed by Scott.

Yoba

proc sort data=test1 out=test2;
by price;
run;

data test2(drop=notix);
set test2;
by price;
if first.price then tot=0;
tot+notix;
if last.price then output;
run;

proc means data=test1 noprint nway missing;
var notix;
class price;
output out=test3(drop=_TYPE_) sum(notix)=sum_notix;
run;
Ask a Question
Discussion stats
  • 2 replies
  • 93 views
  • 0 likes
  • 3 in conversation