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 |
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: