## Proc summary

Solved
Super Contributor
Posts: 506

# Proc summary

Good morning,

I have a data with a Target variable and a number of condition variable ( a b c d e f).

All variable having value 1 or 0.

I want to analyze how many observation of Target=1 (and Target=0) for each combination of 2 condition value (a=1, b=1; a=1, b=0...).

My problem is I dont know how to tell SAS to do ab ac ad.... using the proc summary.

The output should look like the one below. However to get it, I have to go a long way and inefficient.

HHC

Obs    a    b    c    Target    _TYPE_    _FREQ_

1    .    0    0       0       0111        2

2    .    0    0       1       0111        1

3    .    0    1       1       0111        1

4    .    1    1       0       0111        2

5    .    1    1       1       0111        2

6    0    .    0       0       1011        1

7    0    .    1       1       1011        2

8    1    .    0       0       1011        1

9    1    .    0       1       1011        1

10    1    .    1       0       1011        2

11    1    .    1       1       1011        1

12    0    0    .       0       1101        1

13    0    0    .       1       1101        1

14    0    1    .       1       1101        1

15    1    0    .       0       1101        1

16    1    0    .       1       1101        1

17    1    1    .       0       1101        2

18    1    1    .       1       1101        1

data
have;

input
Target a b c d e f ;

datalines;

0 1 1 1 1 1 1

1 0 0 1 1 0 0

1 1 0 0 0 1 1

0 1 1 1 1 0 0

0 0 0 0 1 0 0

1 0 1 1 0 1 0

0 1 0 0 0 0 0

1 1 1 1 1 1 1

;;;;

run;

Accepted Solutions
Solution
‎06-26-2013 02:19 PM
Posts: 3,852

## Re: Proc summary

What if you combine CLASS TYPES and BY TARGET; The only difference the value of _TYPE_, but it is 1 for all target anyway.

data have;
input target a b c d e f ;
datalines;
0 1 1 1 1 1 1
1 0 0 1 1 0 0
1 1 0 0 0 1 1
0 1 1 1 1 0 0
0 0 0 0 1 0 0
1 0 1 1 0 1 0
0 1 0 0 0 0 0
1 1 1 1 1 1 1
;;;;
run;
proc sort data=have;
by target;
run;
proc summary data=have chartype;

by target;
class a b c d e f;
ways 2;

output out=bytar1;
run;
proc sort;

by _type_ target;
run;
proc summary data=have chartype;

class target a b c d e f;
ways 3;

output out=tar1(where=(first(_type_) eq '1'));
run;
proc compare base=bytar1(drop=_type_) compre=tar1 listequalvars;

run;

All Replies
Super User
Posts: 23,776

## Re: Proc summary

Same answer as before, look up the options in WAYS and TYPES so you understand what it's doing.

Then develop your filter criteria for the output data set either using a where statement and the _type_ variable or using TYPES statement.

data have;

input Target a b c d e f ;

datalines;

0 1 1 1 1 1 1

1 0 0 1 1 0 0

1 1 0 0 0 1 1

0 1 1 1 1 0 0

0 0 0 0 1 0 0

1 0 1 1 0 1 0

0 1 0 0 0 0 0

1 1 1 1 1 1 1

;

data have2;

set have;

count=1;

run;

proc means data=have2 noprint;

class a b c d e f target;

var count;

ways;

output out=test1 (where=(target ne .)) sum(target)=sum_target;

run;

Super Contributor
Posts: 506

## Re: Proc summary

Thanks, Reeza.

It is kind of similar to my approach below where we tell SAS not to include target=.

What make me uncomfortable is we treat target and all condition variable the same at the beginning and for a large data, I afraid it will create a lot of work.

proc summary data=have chartype;

class a b c d e f target;

ways 3;

output  out=sumtest;

run;

data sumtest; set sumtest;

if target=. then delete; run;

Super User
Posts: 23,776

## Re: Proc summary

```hhchenfx wrote:

What make me uncomfortable is we treat target and all condition variable the same at the beginning and for a large data, I afraid it will create a lot of work.

```

Can you explain the above further, I don't understand.

Solution
‎06-26-2013 02:19 PM
Posts: 3,852

## Re: Proc summary

What if you combine CLASS TYPES and BY TARGET; The only difference the value of _TYPE_, but it is 1 for all target anyway.

data have;
input target a b c d e f ;
datalines;
0 1 1 1 1 1 1
1 0 0 1 1 0 0
1 1 0 0 0 1 1
0 1 1 1 1 0 0
0 0 0 0 1 0 0
1 0 1 1 0 1 0
0 1 0 0 0 0 0
1 1 1 1 1 1 1
;;;;
run;
proc sort data=have;
by target;
run;
proc summary data=have chartype;

by target;
class a b c d e f;
ways 2;

output out=bytar1;
run;
proc sort;

by _type_ target;
run;
proc summary data=have chartype;

class target a b c d e f;
ways 3;

output out=tar1(where=(first(_type_) eq '1'));
run;
proc compare base=bytar1(drop=_type_) compre=tar1 listequalvars;

run;
Super Contributor
Posts: 506

## Re: Proc summary

Thank you, Data_null_.

I think it works nicely.

HHC

🔒 This topic is solved and locked.