Help using Base SAS procedures

How to calculate cumulative variable by group?

Reply
N/A
Posts: 0

How to calculate cumulative variable by group?

DATA Temp;
INPUT Group Salary;
CARDS;
1 5000
1 6000
1 2100
2 1110
2 5000
2 5000
3 5000
3 5000
;
RUN;

Data Temp1;
set Temp;
Cum_salary + Salary;
RUN;

But how can i calculate cumulative salary by group?
Super Contributor
Super Contributor
Posts: 3,174

Re: How to calculate cumulative variable by group?

Have you looked at PROC FREQ with the OUT= option?

Scott Barry
SBBWorks, Inc.

Recommended Google advanced search argument:

proc freq cumulative frequency site:sas.com
N/A
Posts: 0

Re: How to calculate cumulative variable by group?

Data Temp1;
set Temp;
by group;
if first.Group then Cum_salary=Salary;
else Cum_salary + Salary;
RUN;
N/A
Posts: 0

Re: How to calculate cumulative variable by group?

Thanks~

But if set two group?
It seems no effect......please~

DATA Temp;
INPUT Group1 Group2 Salary;
CARDS;
1 A 5000
1 A 6000
1 B 2100
2 A 1110
2 B 5000
2 B 5000
3 A 5000
3 A 5000
;
RUN;

Data Temp1;
set Temp;
by Group1 Group2;
if first.Group1 & first.Group2 then cum_salary= salary;
else cum_salary+ salary;
run;
N/A
Posts: 0

Re: How to calculate cumulative variable by group?

try this.

DATA Temp;
INPUT Group1 Group2 $ Salary;
CARDS;
1 A 5000
1 A 6000
1 B 2100
2 A 1110
2 B 5000
2 B 5000
3 A 5000
3 A 5000
;
RUN;

proc sort data=temp;
by Group1 Group2;
run;

Data Temp1;
set Temp;
by Group1 Group2;
if first.Group2 then cum_salary= salary;
else cum_salary+ salary;
run;
N/A
Posts: 0

Re: How to calculate cumulative variable by group?

THANKS~
Ask a Question
Discussion stats
  • 5 replies
  • 1282 views
  • 0 likes
  • 2 in conversation