BookmarkSubscribeRSS Feed
LOLO
Obsidian | Level 7

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

 

 

5 REPLIES 5
PaigeMiller
Diamond | Level 26

You can use the formats WORDF. or FRACT.

--
Paige Miller
Reeza
Super User

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

 

 

LOLO
Obsidian | Level 7

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  
PaigeMiller
Diamond | Level 26

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
Reeza
Super User

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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1608 views
  • 1 like
  • 3 in conversation