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!!
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.
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.
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;