BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BrahmanandaRao
Lapis Lazuli | Level 10

/*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;

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
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;

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20
data want;  
   set cal;
   if 3 le id le 8 then do;
      r+marks;
   end;
run;
BrahmanandaRao
Lapis Lazuli | Level 10

HI Draycut

 

i donot want to cumulative sum 

just total sum from id 3 to id 8 only

 

 

Regards,

ANAND

PeterClemmensen
Tourmaline | Level 20
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;
BrahmanandaRao
Lapis Lazuli | Level 10

HI Draycut

 

Brilliant code  thank you for your tremendous response

 

 

Regards,

ANAND

ballardw
Super User

And another approach:

proc means data=cal sum;
   where 3 le id le 8;
   var marks;
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

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 5 replies
  • 1245 views
  • 1 like
  • 3 in conversation