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.
Thank you for your help.
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;
What if you combine CLASS TYPES and BY TARGET; The only difference the value of _TYPE_, but it is 1 for all target anyway.
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;
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;
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.
What if you combine CLASS TYPES and BY TARGET; The only difference the value of _TYPE_, but it is 1 for all target anyway.
Thank you, Data_null_.
I think it works nicely.
HHC
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.