turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- Need help with this question

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-30-2012 07:06 PM

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

Accepted Solutions

Solution

05-31-2012
09:00 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-31-2012 09:00 AM

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;

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-30-2012 07:42 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-31-2012 01:19 AM

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.

Solution

05-31-2012
09:00 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-31-2012 09:00 AM

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-31-2012 01:18 PM

Hi SAS_Bigot,

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