/*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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.