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
- /
- code for computing summation variable

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

3 weeks ago

I tried the following code to sum STATISTIC_ATTRIBUTE_VAL if SORT_ORDER is a certain value.

```
DATA TABS_counts ;
*set TABS_counts;
retain pos_sum;
IF SORT_ORDER = 1121 then do;
pos_sum=sum(pos_sum,STATISTIC_ATTRIBUTE_VAL);END;
RUN;
```

The output is a blank. What is the proper method to bring in SORT_ORDER and STATISTIC_ATTRIBUTE_VAL which are in created tables above? Thanks.

Accepted Solutions

Solution

3 weeks ago

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

3 weeks ago

Reeza, thank you for the quick reply. proc means does provide some stats, however, I'm trying to sum up a column STATISTIC_ATTRIBUTE_VAL when SORT_ORDER matches different values.

Thanks for pointing me in the right direction. The code I used is:

proc means data=WORK.QUERY_FOR_COUNTS MEAN SUM MAXDEC=2;

where SORT_ORDER = 1121;

var STATISTIC_ATTRIBUTE_VAL;

run;

Regards,

capam

Thanks for pointing me in the right direction. The code I used is:

proc means data=WORK.QUERY_FOR_COUNTS MEAN SUM MAXDEC=2;

where SORT_ORDER = 1121;

var STATISTIC_ATTRIBUTE_VAL;

run;

Regards,

capam

All Replies

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

3 weeks ago

What exactly are you trying to do?

And why did you comment out the SET statement? That means you won't have any data to work with...is there a reason to not use proc means?

```
proc means data=tabs_count;
where sort_order = 1121;
var pos_sum;
output out=want sum=statistic_attribute_val;
run;
```

capam wrote:

I tried the following code to sum STATISTIC_ATTRIBUTE_VAL if SORT_ORDER is a certain value.

`DATA TABS_counts ; *set TABS_counts; retain pos_sum; IF SORT_ORDER = 1121 then do; pos_sum=sum(pos_sum,STATISTIC_ATTRIBUTE_VAL);END; RUN;`

The output is a blank. What is the proper method to bring in SORT_ORDER and STATISTIC_ATTRIBUTE_VAL which are in created tables above? Thanks.

Solution

3 weeks ago

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

3 weeks ago

Thanks for pointing me in the right direction. The code I used is:

proc means data=WORK.QUERY_FOR_COUNTS MEAN SUM MAXDEC=2;

where SORT_ORDER = 1121;

var STATISTIC_ATTRIBUTE_VAL;

run;

Regards,

capam

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

3 weeks ago

capam wrote:

Reeza, thank you for the quick reply. proc means does provide some stats, however, I'm trying to sum up a column STATISTIC_ATTRIBUTE_VAL when SORT_ORDER matches different values.

Thanks for pointing me in the right direction. The code I used is:

proc means data=WORK.QUERY_FOR_COUNTS MEAN SUM MAXDEC=2;

where SORT_ORDER = 1121;

var STATISTIC_ATTRIBUTE_VAL;

run;

Regards,

capam

Still have not shown any starting data. Or a log.

You say "when SORT_ORDER matches different values". Is this supposed to matching values in another data set somewhere?

And you may even want to show how you build WORK.QUERY_FOR_COUNTS. It may be that the input data to that set is actually what you want to sum from.

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

3 weeks ago

```
proc means data=WORK.QUERY_FOR_COUNTS MEAN SUM MAXDEC=2;
class sort_order;
var STATISTIC_ATTRIBUTE_VAL;
run;
```

My guess is that's what s/he needs.