BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Merdock
Quartz | Level 8

Hello,

 

I have the following dataset and I was wondering how can I add a row at the bottom with the totals? 

data have;
input VISIT SITE$ N EXPCT OCCRD PERCENT OCCPCT$;
datalines;
1	AAA	11	10	7	70	7(70%)
2	AAA	11	0	0	0	0(0%)
1	BBB	14	5	5	100	5(100%)
2	BBB	14	4	2	50	2(50%)
1	CCC	80	46	39	84.783	39(84.8%)
2	CCC	80	0	0	0	0(0%)
;
run;
proc print data=have; run;

I want my final output (in Word) to look like this:

Merdock_0-1682532097818.png

Where the percentage in the Total row comes from division by the Total Site N so: 48.6%=51/105, and 1.9%=2/105.

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

This should work. I consider something like the text string 7(70%) to be such a poor way to display data that I haven't programmed it. Of course, you can program it if you'd like. I have also fixed a spelling error.

 

proc summary data=have nway;
    class visit;
    var n expct occrd;
    output out=_stats_ sum=;
run;

data have1;
    length site $ 5;
    set have _stats_(drop=_:);
    if missing(site) then site='Total';
    if site='Total' then percent=occrd/n;
    else percent=percent/100;
run;

proc report data=have1;
    columns site n visit,(occrd percent expct);
    define site/group "Site" order=data;
    define n/group "N";
    define visit/across "Yearly Visits";
    define occrd/sum "Total Occurred";
    define percent/sum "Percent" format=percent8.1;
    define expct/sum "Total Expected";
run;
--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Is your question:

 

How to produce the report shown?

 

Or, is it as you have stated, how to produce a data set that looks somewhat like the report? (If so, why?)

--
Paige Miller
Merdock
Quartz | Level 8

@PaigeMiller, the question is how to obtain the report shown based on the dataset have (specifically how to add that final row with Totals at the bottom). Thanks!

PaigeMiller
Diamond | Level 26

This should work. I consider something like the text string 7(70%) to be such a poor way to display data that I haven't programmed it. Of course, you can program it if you'd like. I have also fixed a spelling error.

 

proc summary data=have nway;
    class visit;
    var n expct occrd;
    output out=_stats_ sum=;
run;

data have1;
    length site $ 5;
    set have _stats_(drop=_:);
    if missing(site) then site='Total';
    if site='Total' then percent=occrd/n;
    else percent=percent/100;
run;

proc report data=have1;
    columns site n visit,(occrd percent expct);
    define site/group "Site" order=data;
    define n/group "N";
    define visit/across "Yearly Visits";
    define occrd/sum "Total Occurred";
    define percent/sum "Percent" format=percent8.1;
    define expct/sum "Total Expected";
run;
--
Paige Miller
Merdock
Quartz | Level 8
this works perfectly, thank you so much!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1019 views
  • 1 like
  • 2 in conversation