🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 01-27-2021 03:52 AM
(3165 views)
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 🙂
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data want;
set have;
by SPcislo;
if first.SPcislo then c = 0;
c + cislo;
run;
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data want;
set have;
by SPcislo;
if first.SPcislo then c = 0;
c + cislo;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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)