How can I sum values of a variable only when there appear replicated dates per ID?
Suppose to have:
data have;
input ID :$20. Date :date09. Value;
format Date date9. Value;
cards;
0001 13JAN2017 0
0001 22FEB2017 1
0001 22FEB2017 1
0001 30JAN2019 0
0002 28DEC2014 1
0002 28DEC2014 2
0002 28DEC2014 1
0002 28DEC2014 0
0003 15DEC2021 0
0003 16DEC2021 1
;
The desired output should be:
data want;
input ID :$20. Date :date09. Value;
format Date date9. Value;
cards;
0001 13JAN2017 0
0001 22FEB2017 2
0001 30JAN2019 0
0002 28DEC2014 4
0003 15DEC2021 0
0003 16DEC2021 1
;
Just sum over ALL of the groups. The groups that only have one observation are not really any different than those with multiple observations.
proc summary data=have ;
by id date;
var value;
output out=want sum=;
run;