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
- /
- output results as a fraction

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

09-21-2017 03:42 PM

I am tasked with outputting results for a monetary amount in a fraction format: numerator/denominator.

If my denominator is my total sample and my numerator is flag=1, my output needs to look like the following:

total monetary amount when flag=1/total monetary amount for total sample

I am not sure where to begin. Any ideas would be appreciated!!

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

Posted in reply to LOLO

09-21-2017 03:48 PM

You can use the formats WORDF. or FRACT.

--

Paige Miller

Paige Miller

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

Posted in reply to LOLO

09-21-2017 04:05 PM

And if you can't figure it out using the formats, show some example data and what you want to see.

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

Posted in reply to Reeza

09-21-2017 04:17 PM

Thank you! ok, this is an example of the data and what I would like to see as the result.

data: | ||

type | cost | flag |

a | 20 | 1 |

a | 30 | 0 |

a | 40 | 0 |

b | 10 | 1 |

b | 15 | 1 |

b | 70 | 0 |

results: | ||

a | 20/90 | |

b | 25/95 |

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

Posted in reply to LOLO

09-21-2017 04:34 PM - edited 09-21-2017 04:35 PM

PROC SUMMARY will provide you with the SUM in each value of TYPE. It can also sum the flagged values by each value of TYPE.

Then you can merge the results of the two PROC SUMMARY, and produce the output 20/90. You wouldn't even need a FORMAT, you can do it in a DATA step.

As a general rule, you would be wise to show your data in the original problem statement instead of providing later in the thread.

--

Paige Miller

Paige Miller

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

Posted in reply to LOLO

09-21-2017 04:49 PM

Here's an example that uses SQL

```
data have;
input type $ cost flag;
cards;
a 20 1
a 30 0
a 40 0
b 10 1
b 15 1
b 70 0
;
run;
proc sql;
create table want as
select type, sum(cost*flag) as numerator, sum(cost) as denominator,
CALCULATED NUMERATOR/ CALCULATED DENOMINATOR AS FRAC FORMAT=FRACT.,
CATX("/", put(calculated numerator, 8.), put(calculated denominator, 8.)) as frac_text
from have
group by type;
quit;
```