BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hhchenfx
Barite | Level 11

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;

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

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;

View solution in original post

5 REPLIES 5
Reeza
Super User

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;

hhchenfx
Barite | Level 11

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;

Reeza
Super User

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.

data_null__
Jade | Level 19

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;
hhchenfx
Barite | Level 11

Thank you, Data_null_.

I think it works nicely.

HHC

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
  • 5 replies
  • 830 views
  • 3 likes
  • 3 in conversation