BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
LorenaPalacios
Calcite | Level 5

Hi!

Excuse me, but my English is not very good
I hope you understand the question

 

I have the following data table:

Table_A

Stationequipmentvolume
ST_aeq_a_110
ST_aeq_a_29
ST_aeq_a_35
ST_beq_b_110
ST_beq_b_23
ST_ceq_c_115
ST_ceq_c_214

 

I need to accumulate the value of the Volume column and keep all the records so that the result is shown as the following table

 

Table_B   
Stationequipmentvolumecumulative
ST_aeq_a_11010
ST_aeq_a_2919
ST_aeq_a_3524
ST_beq_b_11010
ST_beq_b_2313
ST_ceq_c_11515
ST_ceq_c_21429

 

I really need to solve this problem.
Thank you very much!

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Try

 

by descending Station 	descending equipment;

View solution in original post

8 REPLIES 8
novinosrin
Tourmaline | Level 20

cumulative+volume;

run;

 

reset cumulative to zero when reading a new by group

LorenaPalacios
Calcite | Level 5
 
 
I tried with the following sentence but it leaves me a record for each station and I need only to accumulate in each station cut the value of the equipment
 
data new;
   set pru;
   by sistema_nombre  ;
 
   if first.sistema_nombre then total=0;
  
   total + volumen;
   if last.sistema_nombre then output;
   drop volumen;
run;
novinosrin
Tourmaline | Level 20
data have;
input Station $	equipment $	volume;
cards;
ST_a	eq_a_1	10
ST_a	eq_a_2	9
ST_a	eq_a_3	5
ST_b	eq_b_1	10
ST_b	eq_b_2	3
ST_c	eq_c_1	15
ST_c	eq_c_2	14
;

data want;
set have;
by Station 	equipment;
if first.Station then cumu=volume;
else cumu+volume;
/*if last.Station;*/
run;
LorenaPalacios
Calcite | Level 5
 
I really need to sort it by station and volume but volumen . When I enter the sentence "by station volume" it indicates the error "BY variables are not properly sorted on data".
Table_a is sorted descending by station and volume. Any suggestions? thank you very much!
novinosrin
Tourmaline | Level 20

Try

 

by descending Station 	descending equipment;
LorenaPalacios
Calcite | Level 5

Thank you very much!!!!! it worked perfectly!!

novinosrin
Tourmaline | Level 20

Welcome to the SAS forum and I hope you have fun. Take care!

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
  • 8 replies
  • 2467 views
  • 0 likes
  • 2 in conversation