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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 20 replies
  • 1479 views
  • 7 likes
  • 6 in conversation