SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Cumulative count based on other variable

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Cumulative count based on other variable

[ Edited ]
DATA ALL ;
SET ALL ;
by pa_id sa_id admin notsorted;
IF first.admin then seq +1;
run;

Dear all, 

 I need your unreserved help. I am using SAS version 9.4.  I want to count admin variable in cumulative fashion for value "o" by pa_id, sa_id, time. 

the structure of the data is given below

 

prop data.PNG

 

I am expecting like this 

 

Capture1.PNG


Accepted Solutions
Solution
a week ago
PROC Star
Posts: 1,328

Re: Cumulative count based on other variable

Posted in reply to novinosrin
data have;
input pa_id	sa_id 	time	Admin $;
cards;
1	11	23	o
1	11	36	o
1	11	82	p
1	12	45	o
1	12	55	p
1	12	67	o
1	12	70	o
1	12	90	o
2	13	36	o
2	13	46	o
2	13	59	p
2	14	25	p
2	14	34	o
2	14	40	p
;
data want;
set have;
by pa_id sa_id;
if first.sa_id then do; count=0;cum_count=1;end;
else cum_count+1;
if admin='o' then count+1;
run;

View solution in original post


All Replies
PROC Star
Posts: 1,328

Re: Cumulative count based on other variable

[ Edited ]
Posted in reply to Yilikal_Tesfaye

I'm afraid pics or screen shots doesn't help in ease of copy pasting the data values

 

 

untested

data want;
set have;
by pa_id sa_id;
if first.sa_id then do; count=0;cum_count=1;end;
else cum_count+1;
if admin='o' then count+1;
run;

Solution
a week ago
PROC Star
Posts: 1,328

Re: Cumulative count based on other variable

Posted in reply to novinosrin
data have;
input pa_id	sa_id 	time	Admin $;
cards;
1	11	23	o
1	11	36	o
1	11	82	p
1	12	45	o
1	12	55	p
1	12	67	o
1	12	70	o
1	12	90	o
2	13	36	o
2	13	46	o
2	13	59	p
2	14	25	p
2	14	34	o
2	14	40	p
;
data want;
set have;
by pa_id sa_id;
if first.sa_id then do; count=0;cum_count=1;end;
else cum_count+1;
if admin='o' then count+1;
run;
Highlighted
New Contributor
Posts: 4

Re: Cumulative count based on other variable

Posted in reply to novinosrin

Thank you in advance.

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 151 views
  • 2 likes
  • 2 in conversation