/*Find the sum of all marks from id 3 to id 8 by using Datastep*/
data cal;
file print;
input id marks;
cards;
1 97
2 95
3 45
4 54
5 45
6 48
7 47
8 47
9 45
10 58
;
run;
data cal1 ;
set cal;
do id= 3 to 8
r=sum(of 3,4,5,6,7,8);
run;
data cal;
input id marks;
cards;
1 97
2 95
3 45
4 54
5 45
6 48
7 47
8 47
9 45
10 58
;
run;
data want;
set cal end=lr;
if 3 le id le 8 then do;
r+marks;
end;
if lr then output;
keep r;
run;
proc print;
run;
data want;
set cal;
if 3 le id le 8 then do;
r+marks;
end;
run;
HI Draycut
i donot want to cumulative sum
just total sum from id 3 to id 8 only
Regards,
ANAND
data cal;
input id marks;
cards;
1 97
2 95
3 45
4 54
5 45
6 48
7 47
8 47
9 45
10 58
;
run;
data want;
set cal end=lr;
if 3 le id le 8 then do;
r+marks;
end;
if lr then output;
keep r;
run;
proc print;
run;
HI Draycut
Brilliant code thank you for your tremendous response
Regards,
ANAND
And another approach:
proc means data=cal sum; where 3 le id le 8; var marks; run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.