Help using Base SAS procedures

adding a variable

Reply
N/A
Posts: 0

adding a variable

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
Super Contributor
Super Contributor
Posts: 3,174

Re: adding a variable

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.
N/A
Posts: 0

Re: adding a variable

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.
SAS Super FREQ
Posts: 8,739

Re: adding a variable

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]
N/A
Posts: 0

Re: adding a variable - program worked!

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!
Ask a Question
Discussion stats
  • 4 replies
  • 143 views
  • 0 likes
  • 3 in conversation