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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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