Hello, i want to ask how can i sum each previous rows by variable SPCislo, here is sample of data:
PK | DatumPodpisu | SPcislo | cislo |
501377324233203 | 23Sep2019 0:00:00,000 | 5100543 | 10 |
501377324233208 | 23Sep2019 0:00:00,000 | 5100543 | 10 |
501377324233213 | 23Sep2019 0:00:00,000 | 5100543 | 10 |
501377324274981 | 23Sep2019 0:00:00,000 | 5100543 | 10 |
501377324461518 | 10Mar2020 0:00:00,000 | 555 | 38,0352 |
501377324452148 | 11Mar2020 0:00:00,000 | 555 | 11,543 |
501377324458471 | 12Mar2020 0:00:00,000 | 555 | 195,7242 |
And i want to calculated sum of each row by rows group by SPCislo, like this:
PK | DatumPodpisu | SPcislo | cislo | how to calculate this??? |
501377324233203 | 23Sep2019 0:00:00,000 | 5100543 | 10 | 10 |
501377324233208 | 23Sep2019 0:00:00,000 | 5100543 | 10 | 20 |
501377324233213 | 23Sep2019 0:00:00,000 | 5100543 | 10 | 30 |
501377324274981 | 23Sep2019 0:00:00,000 | 5100543 | 10 | 40 |
501377324461518 | 10Mar2020 0:00:00,000 | 555 | 38,0352 | 38,0352 |
501377324452148 | 11Mar2020 0:00:00,000 | 555 | 11,543 | 49,5782 |
501377324458471 | 12Mar2020 0:00:00,000 | 555 | 195,7242 | 245,3024 |
Thanks all for help 🙂
data want;
set have;
by SPcislo;
if first.SPcislo then c = 0;
c + cislo;
run;
data want;
set have;
by SPcislo;
if first.SPcislo then c = 0;
c + cislo;
run;
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)
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.