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
- /
- SAS Procedures
- /
- proc report: total for computed variable

Topic Options

- 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
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-01-2012 04:13 AM

Dear all,

I have a proc report with a computed variable for which I need a total in the last row.

options missing = '';

proc report data=mydata;

column firstfield hiddenfield myfield [some more fields];

define firstfield / display noprint;

define hiddenfield / display noprint;

define myfield / computed;

[some more fields]

compute myfield;

if firstfield eq 1 then do;

myfield = hiddenfield;

end;

else do;

myfield = . ;

end;

endcomp;

run;

The data behind this looks like this (first 2 columns - and the third column should be the computed field):

the idea behind this is to suppress repeated values and sum in the total only the distinct values per firstfield = 1

firstfield | hiddenfield | myfield |
---|---|---|

1 | 92 | 92 |

0 | 92 | |

0 | 92 | |

1 | 236 | 236 |

0 | 236 | |

0 | 236 | |

0 | 236 |

Now when I do a rbreak the total for hiddenfield is 3*92 + 4*236. But for myfield I need the total 1*92 + 1*236.

Unfortunaltely the SAS automatism does a missing value. I'd love to have the rbreak just as a sum of the myfield values.

The only idea I had was using the trick of aggregating the values by temporary variables:

compute before;

mytotal = 0;

endcomp;

compute myfield;

mytotal = myfield + mytotal;

if _break_ eq "_RBREAK_ then do;

myfield = mytotal;

end;

endcomp;

Does anybody know some other solution?

Best wishes

Eva

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

02-01-2012 10:55 AM

Hi,

If you know that the values in HIDDENFIELD will ALWAYS be the same, then you could use the MEAN statistic to generate the total you want without creating the MYFIELD column.

But, since you are hiding the values anyway, why not just change HIDDENFIELD in a DATA step program (or create a new variable) using FIRST. processing so you only keep the first value, then your sum will work correctly? (if you define your variable as SUM, not DISPLAY).

cynthia