SAS Enterprise Guide

Desktop productivity for business analysts and programmers
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)

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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
  • 3166 views
  • 2 likes
  • 3 in conversation