Hi All,
I have the dataset:
data have;
input claim_id $ value;
cards;
3 2
3 2
4 5
4 8.5
4 2.3
123 0
123 1
125 2
125 0
125 3
;
run;
I would like to get the product of the value for each claim_id to get the want dataset below. I was hoping proc summary had a product option but that doesn't seem to be the case
data want;
input claim_id $ value;
cards;
3 4
4 97.75
123 0
125 0
;
run;
Thanks!
data have;
input claim_id $ value;
cards;
3 2
3 2
4 5
4 8.5
4 2.3
123 0
123 1
125 2
125 0
125 3
;
run;
data want;
_n_=1;
do until(last.claim_id);
set have;
by claim_id notsorted;
value=value*_n_;
_n_=value;
end;
run;
claim_id | value |
---|---|
3 | 4.00 |
4 | 97.75 |
123 | 0.00 |
125 | 0.00 |
Works great too, thanks!
data have;
input claim_id $ value;
cards;
3 2
3 2
4 5
4 8.5
4 2.3
123 0
123 1
125 2
125 0
125 3
;
run;
data want;
_n_=1;
do until(last.claim_id);
set have;
by claim_id notsorted;
value=value*_n_;
_n_=value;
end;
run;
claim_id | value |
---|---|
3 | 4.00 |
4 | 97.75 |
123 | 0.00 |
125 | 0.00 |
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.