BookmarkSubscribeRSS Feed
ssas
Calcite | Level 5
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
.
.
.
.
.
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
deleted_user
Not applicable
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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 1103 views
  • 0 likes
  • 3 in conversation