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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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