BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I have a variable called tot_ch which gives total charges. which statement should I used to get the total number of tot_ch (total charges)by each site (site of facility that is charging). I need to sum up all the charges (tot_ch) by site (site).

thank you so much for your help.

Regards,
RQ
4 REPLIES 4
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
It would be useful to see a data-sample the INPUT_DATA (columns/variables named) and the desired OUTPUT columns represented in your query/post reply.

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
This may help.

data abc;/*example dataset*/
input site total_ch;
datalines;

1 5
1 13
1 12
1 12
2 34
2 22
2 44
2 77
3 12
3 11
3 12
3 12
;

data xyz; set abc;
by site;
if first.site then count=0; count+1;
if first.site then sum_total=total_ch; else sum_total+total_ch;
run;

proc sql; create table def as
select site, count, max (sum_total) as maxtotal
from xyz
group by site
having sum_total= calculated maxtotal;
quit;

proc print data=def; run;

This will give you the total counts (# of total charges) per site as well as the sum total charges by each site.
Cynthia_sas
SAS Super FREQ
Hi:
Given this data, you can also use several different SAS procedures WITHOUT needing the DATA step or the PROC SQL step. Programs and output are below based on the ABC data. The doc describes how to make output data sets from any of these 3 procedures. Pick the one whose look and feel you like best.

cynthia

[pre]
* Proc Report Program;

proc report data=abc nowd;
column site n total_ch total_ch=maxtot total_ch=mintot total_ch=avgtot;
define site / group;
define n / 'Count';
define total_ch/ sum "Sum Total";
define maxtot / max "Max Total";
define mintot / min "Min Total";
define avgtot / mean "Avg Total";
run;

******Proc Report Output******
site Count Sum Total Max Total Min Total Avg Total
1 4 42 13 5 10.5
2 4 177 77 22 44.25
3 4 47 12 11 11.75


** Proc Means Program;
proc means data=abc n sum max min mean;
class site;
var total_ch;
run;


*******Proc Means Output******
The MEANS Procedure

Analysis Variable : total_ch

N
site Obs N Sum Maximum Minimum Mean
-----------------------------------------------------------------------------------------
1 4 4 42.0000000 13.0000000 5.0000000 10.5000000

2 4 4 177.0000000 77.0000000 22.0000000 44.2500000

3 4 4 47.0000000 12.0000000 11.0000000 11.7500000
-----------------------------------------------------------------------------------------


*Proc Tabulate Program;
proc tabulate data=abc;
class site;
var total_ch;
table site,
total_ch*(n sum max min mean);
run;


****** Proc Tabulate Output******

+-------------------------------------------+
| | total_ch |
| +----------------------------------+
| | N | Sum | Max | Min | Mean |
+--------+------+------+------+------+------+
|site | | | | | |
+--------+ | | | | |
|1 | 4.00| 42.00| 13.00| 5.00| 10.50|
+--------+------+------+------+------+------+
|2 | 4.00|177.00| 77.00| 22.00| 44.25|
+--------+------+------+------+------+------+
|3 | 4.00| 47.00| 12.00| 11.00| 11.75|
+-------------------------------------------+


[/pre]
deleted_user
Not applicable
Thank you very much for your help. It worked and I think that by using any of the programs created it would work.

Thanks again!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 702 views
  • 0 likes
  • 3 in conversation