BookmarkSubscribeRSS Feed
novinosrin
Tourmaline | Level 20

HI @David_Billa  I do not have clue of what is DI studio, however noticing the mention by @MCoopmans  DI uses SQL, you could perhaps attempt to use the SQL solution below in your DI studio. Would the below help?

 


data have;
input VALUE;
cards;
20
20
20
20
20
;


proc sql;
create view temp as
select *,monotonic() as rn
from have;
create table want as
select sum(b.value) as sum
from temp a left join temp b
on b.rn>=a.rn
group by a.rn;
quit;

 

David_Billa
Rhodochrosite | Level 12

Great! How to tweak your code so that I don't end up with creating/renaming the variable which holds sum value (VALUE) and also have to group by on three variables?

novinosrin
Tourmaline | Level 20

to hold sum value as value, there isn't much to do, except

select sum(b.value) as value

Not sure, what you mean by- and also have to group by on three variables? Do you mean something like

select x,y,z,sum(value) as value


group by a.rn, x,y,z;

 

David_Billa
Rhodochrosite | Level 12

yes, I want like you mentioned in my previous post but it is not producing the desired Output as it is summing the values from all the observations and then doing  Group by instead sum values only from current observations and do the Group by

David_Billa
Rhodochrosite | Level 12
If you group by row number then you will get the same results as your
source dataset
novinosrin
Tourmaline | Level 20

Basically the logic

from temp a left join temp b
on b.rn>=a.rn

accommodates the values for a group. The SQL processor see's the following after the JOIN

rn VALUE brn 
1 20 1 
1 20 2 
1 20 3 
1 20 4 
1 20 5 
2 20 2 
2 20 3 
2 20 4 
2 20 5 
3 20 3 
3 20 4 
3 20 5 
4 20 4 
4 20 5 
5 20 5 

Then the summarization takes place

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 20 replies
  • 2204 views
  • 7 likes
  • 6 in conversation