data have;
input ID GPS $ Open $ Store;
cards;
1 89503 Y 1
1 12353 Y 1
1 06834 N 2
2 95736 N 2
2 01475 Y 3
3 64758 Y 4
;
proc sql;
create table want as
select *, count(id) as count
from have
group by id
order by id,store;
quit ;
data have;
input ID GPS $ Open $ Store;
cards;
1 89503 Y 1
1 12353 Y 1
1 06834 N 2
2 95736 N 2
2 01475 Y 3
3 64758 Y 4
;
proc sql;
create table want as
select *, count(id) as count
from have
group by id
order by id,store;
quit ;
Hi @Mikkel_madsen I am sharing another smart stuff taught by genius @mkeintz to whom I owe a lot of my learning
data have;
input ID GPS $ Open $ Store;
cards;
1 89503 Y 1
1 12353 Y 1
1 06834 N 2
2 95736 N 2
2 01475 Y 3
3 64758 Y 4
;
data want;
set have(in=a) have(in=b);
by id;
retain count;
if first.id then count=0;
if a then count=sum(count,1);
if b;
run;
And, in the pursuit of terminal cuteness, one can:
data have;
input ID GPS $ Open $ Store;
cards;
1 89503 Y 1
1 12353 Y 1
1 06834 N 2
2 95736 N 2
2 01475 Y 3
3 64758 Y 4
;
data want;
set have(in=countme) have(in=keepme);
by id;
if first.id then count=0;
count+countme;
if keepme;
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.