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
- /
- Base SAS Programming
- /
- sum of column

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

04-11-2017 11:27 AM

Hi,

I came across one dataset which consist of

state region1 region2 region3

abc 20 30 50

def 40 30 30

ghi 25 35 40

xyz 30 45 20

i need to find out the sum of each region and which region is largest among the 3 regions?

Can some one help me ?

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

04-11-2017 11:35 AM

Use proc means

```
data have;
input state $ region1 region2 region3;
datalines;
abc 20 30 50
def 40 30 30
ghi 25 35 40
xyz 30 45 20
;
proc means data = have sum;
var region1-region3;
run;
```

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

04-12-2017 02:20 AM

Hi dray,

Thanks for your reply, but i am looking for result into new dataset with the variable state and only the region with larger .

will it can be done in data step itself?

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

04-12-2017 03:46 AM

So you want your variable state and the region variable which has the highest sum?

In the example posted, both region 2 and region 3 has sum equal to 140, then what?

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

04-13-2017 03:14 AM

Hi dray,

Yes, i want the result with the variable state and the region variable which has the highest sum.

Apologies , observations was randomly given by me .And unfortunate region 2 and 3 sum become equal. you can change any one number either in region 2 and region 3.

Is this possible to do in the datastep itself?

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

04-11-2017 11:47 AM

```
proc means data=DSN n min max sum;
run;
```

You could generate summarization table for above dataset,

It would give you the sum of each region as well as largest among them