BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
2 REPLIES 2
Cynthia_sas
SAS Super FREQ
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
data_null__
Jade | Level 19
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]

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 2 replies
  • 719 views
  • 0 likes
  • 3 in conversation