BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Pato485
Calcite | Level 5

Hello, i want to ask how can i sum each previous rows by variable SPCislo, here is sample of data:

 

PKDatumPodpisuSPcislocislo
50137732423320323Sep2019 0:00:00,000510054310
50137732423320823Sep2019 0:00:00,000510054310
50137732423321323Sep2019 0:00:00,000510054310
50137732427498123Sep2019 0:00:00,000510054310
50137732446151810Mar2020 0:00:00,00055538,0352
50137732445214811Mar2020 0:00:00,00055511,543
50137732445847112Mar2020 0:00:00,000555195,7242

 

And i want to calculated sum of each row by rows group by SPCislo, like this:

PKDatumPodpisuSPcislocislohow to calculate this???
50137732423320323Sep2019 0:00:00,00051005431010
50137732423320823Sep2019 0:00:00,00051005431020
50137732423321323Sep2019 0:00:00,00051005431030
50137732427498123Sep2019 0:00:00,00051005431040
50137732446151810Mar2020 0:00:00,00055538,035238,0352
50137732445214811Mar2020 0:00:00,00055511,54349,5782
50137732445847112Mar2020 0:00:00,000555195,7242245,3024

 

Thanks all for help 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
data want;
   set have;
   by SPcislo;
   if first.SPcislo then c = 0;
   c + cislo;
run;

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20
data want;
   set have;
   by SPcislo;
   if first.SPcislo then c = 0;
   c + cislo;
run;
Kurt_Bremser
Super User

Or, very slightly optimized:

data want;
set have;
by SPcislo;
if first.SPcislo
then c = cislo;
else c + cislo;
run;

(at all FIRST. events, there's only one assignment instead of two)

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

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 3431 views
  • 2 likes
  • 3 in conversation