BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PeterBr
Obsidian | Level 7

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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

View solution in original post

3 REPLIES 3
Reeza
Super User
Manual is pretty straightforward.

data want;
set have;
by claim_id;

retain total;

if first.claim_id then total = value;
else total = total * value;

if last.claim_id then output;

run;
PeterBr
Obsidian | Level 7

Works great too, thanks!

novinosrin
Tourmaline | Level 20

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 942 views
  • 1 like
  • 3 in conversation