The SAS Output Delivery System and reporting techniques

Sum a column

Reply
N/A
Posts: 0

Sum a column

I would like to sum multiple variables of 1's and .'s

This is the situation. I have 5 divisions of one variable. so there is a column for type 1, type 2 ... type 5 with a 1 if this obs is that type . else.

The second part is a success column for each type:
type1success, type2success, ... type5success with a 1 if this observation was a success.

I would like to set up a table with 5 rows one for each type and 3 variables like so: ('...' are so u can see the columns)

..........sumoftype1........sumoftype1success........success/type1 (ie success rate)

type 1

type 2




type 5



please let me know if you can help with this. Thanks! Message was edited by: Bryce
SAS Super FREQ
Posts: 8,743

Re: Sum a column

Hi:
You could do this with PROC MEANS (particularly if you want an output dataset) or you could get a report from PROC MEANS, PROC TABULATE or PROC REPORT.

The downside of PROC MEANS is that it is great at making an output dataset, but the dataset might not be in the structure you describe.

The other procedures (TABULATE, REPORT) give you more control over the way the output report would look. The method you choose will depend on whether you want an output dataset (for further analysis) or an output report (for sending out the success results as a summary report).

cynthia
Respected Advisor
Posts: 3,777

Re: Sum a column

Without sample data I cannot interpret your question. You should alway provide sample data with data statement to read it or a data step the generates the data.

I will make a guess perhaps that will further the discussion. I think you have indicator variables type1-type5 and you want to summarize them to get N, Count and percent.

[pre]
*** Gen some data;
proc plan seed=1567462051;
factors id=20 ordered type=1 of 5;
output out=types;
run;
proc transreg data=types design;
model class(type / zero=none);
id id;
output out=Response(drop=_: inter: type);
run;

title 'Does your data look like this?';
proc contents varnum;
proc print;
run;
Title 'Do you want a report like this?';
proc tabulate FORMCHAR="|----|+|---+=|-/\<>*";
var type:;
tables
type1 type2 type3 type4 type5,
(N='N'*f=f2. sum='Success'*f=f7. mean='Rate'*f=f4.3);
run;
[/pre]

[pre]
Obs type1 type2 type3 type4 type5 id

1 1 0 0 0 0 1
2 0 0 0 0 1 2
3 0 0 0 0 1 3
4 0 0 0 1 0 4
5 0 0 0 0 1 5
6 0 0 0 1 0 6
7 0 1 0 0 0 7
8 0 1 0 0 0 8
9 0 0 1 0 0 9
10 0 0 1 0 0 10
11 1 0 0 0 0 11
12 1 0 0 0 0 12
13 0 0 0 0 1 13
14 0 0 1 0 0 14
15 0 0 0 1 0 15
16 0 0 1 0 0 16
17 1 0 0 0 0 17
18 0 1 0 0 0 18
19 0 0 1 0 0 19
20 0 0 1 0 0 20
[/pre]

[pre]
----------------------------------------
| |N |Success|Rate|
|----------------------+--+-------+----|
|type 1 |20| 4|.200|
|----------------------+--+-------+----|
|type 2 |20| 3|.150|
|----------------------+--+-------+----|
|type 3 |20| 6|.300|
|----------------------+--+-------+----|
|type 4 |20| 3|.150|
|----------------------+--+-------+----|
|type 5 |20| 4|.200|
----------------------------------------
[/pre]
Ask a Question
Discussion stats
  • 2 replies
  • 137 views
  • 0 likes
  • 3 in conversation