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

Hi, I looking for help with this question. I have a dataset with columns A and B and want to calculate C such that the final dataset looks something like this:

A   B   C

1   5   (4*5)=20

2   6   (3*5)+(4*6)=39

3   7   (2*5)+(3*6)+(4*8)=56

4   8   (1*5)+(2*6)+(3*7)+(4*8)=70

I will be more than glad to get techie hands on this one for me.

Thanks

kmante

1 ACCEPTED SOLUTION

Accepted Solutions
FloydNevseta
Pyrite | Level 9

Start here:

data want (drop=_:);

input a b;

do _i = 0 to (a-1);

   c = sum( c, (b-_i)*(b-a-_i) );

end;

cards;

1 5

2 6

3 7

4 8

;

run;

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

Shouldn't it be

3   7   (2*5)+(3*6)+(4*7)=56

There are many ways to guess what is required. What would be the result if the dataset contained only the first three lines?

PG

PG
kmante
Calcite | Level 5

Hi PG,

Yes thanks for the correction it should be (4*7)...

The actual dataset contain more observations than the example but the logic should work for the bid data if found for this.

FloydNevseta
Pyrite | Level 9

Start here:

data want (drop=_:);

input a b;

do _i = 0 to (a-1);

   c = sum( c, (b-_i)*(b-a-_i) );

end;

cards;

1 5

2 6

3 7

4 8

;

run;

kmante
Calcite | Level 5

Hi SAS_Bigot,

That was a brilliant and simple answer and works perfect. Thanks a lots.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 541 views
  • 1 like
  • 3 in conversation