BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi

i have a data i want the income sum betweeen where first=1 and last=1;

id inco first last
1 2 1 0
1 2 0 0
2 2 0 1
3 4 1 0
4 6 0 0
5 7 0 1


the output is like this

id inc first last final_tot
1 2 1 0
1 2 0 0
2 2 0 1 4
3 4 1 0
4 6 0 0
5 7 0 1 12
2 REPLIES 2
LinusH
Tourmaline | Level 20
You should explore the use of BY group processing techniques in the data step such as FIRST. and LAST., together with RETAIN.

/Linus
Data never sleeps
deleted_user
Not applicable
in the o/p you have shown ,
you are adding id and inco where last=1.

but you are saying "income sum betweeen where first=1 and last=1"
here is solution.

data i;
input id inco first last;
cards;
1 2 1 0
1 2 0 0
2 2 0 1
3 4 1 0
4 6 0 0
5 7 0 1
;

data i1;
set i;
retain tot 0;
if first=1 then tot = inco;
else if last = 1 then final_tot = tot + inco;
else tot = tot + inco;
drop tot;
run;



o/p - i1

id inc first last final_tot
1 2 1 0
1 2 0 0
2 2 0 1 6
3 4 1 0
4 6 0 0
5 7 0 1 17

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 748 views
  • 0 likes
  • 2 in conversation