BookmarkSubscribeRSS Feed
rahulramesh3321
Calcite | Level 5

Hi Everyone,

 

I am stuck in one problem where I am not able to program it. Sample data is given below : 

 

 

IDA1xB1y Output
AA875000001750000000 87500000
AA0628420515.9 31421025.8
AA0603509371 30175468.55
BB                          40,000               800,000             40,000
BB0720,000 36000
CC                       440,250           8,805,000           440,250
CC0           7,885,000           394,250
CC0           6,458,720           322,936
CC0           2,571,356     128,567.80

 

Output Calculation : 

For AA

OBS         output

1               87500000

2               (87500000/1750000000)*628420515.9 = 31421025.8

3               (87500000 +31421025.8 /1750000000 + 628420515.9) * 603509371 = 30175468.55

 

For CC

OBS        Output

1             440,250

2             (440,250 / 8,805,000)*7,885,000 = 394,250

3              (440,250 + 394,250/ 8,805,000 +7,885,000)*6,458,720 = 322,936

4              (440,250 + 394,250+322,936/ 8,805,000 +7,885,000+6,458,720) * 2,571,356 = 128,567.80

 

I have tried with using lag and cumulative but not able to go beyond obs =2 and also got issue in implementing in the subgroup.

I had a thought of using array and loop but it was making program quite complicated and also not getting the desired output.

 

Please help.

2 REPLIES 2
lalaktgrau
Fluorite | Level 6

hey, can you create a dataset using DATALINES, so I can play with it in SAS?

rahulramesh3321
Calcite | Level 5

Sure,

 

data test;
infile datalines delimiter=',';
input ID$ A1x B1y;
datalines;
AA,87500000,1750000000
AA,0,628420515.9
AA,0,603509371
BB,40000,800000
BB,0,720000
CC,440250,8805000
CC,0,7885000
CC,0,6458720
CC,0,2571356
;

run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1002 views
  • 0 likes
  • 2 in conversation