BookmarkSubscribeRSS Feed
prof_louisa
Calcite | Level 5

I have data set with 10 binary variables (var1-var10), and about 300 observations.

I want to output 9 data sets:

Data set 1: all combinations of the 10 variables taken 2 variables at a time (10 choose 2), so 45 rows

Data set 2: 10 choose 3, so 120 rows

....

Data set 9: 10 choose 10, so just 1 row

Each data set will include all var1-var10, and percent variable that shows how many observations =1 for each combination in data.

For example (for data set of 10 choose 2):

var1      var2         var3     ....       var10           Percent

1           1                                                         3% (percent of 300 observations where var1=1 and var2=1)

1                           1                                         70%

1                                                   1                 5%

.... showing all possible combinations of 10 choose 2

Best way to do this, and can be applied to larger number of variables that would produce larger data sets (i.e. 30 variables, taken 15 at a time = >150 million obs)?

5 REPLIES 5
pradeepalankar
Obsidian | Level 7

hi ,

heres the code which wil generate multiple tables based on no of 1's present in row:

data test;

input a1-a10;

count=sum(of a1-a10);

cards;

1 1 . . . . . . . .

1 1 1 . . . . . . .

1 1 1 1 . . . . . .

1 . . . . . . 1 . .

1 1 1 1 . . . . . .

1 1 1 1 . . . . . .

1 1 1 1 1 . . . . .

1 1 1 1 1 1 . . . .

1 1 1 1 1 1 1 . . .

1 1 1 1 1 1 1 1 . .

1 . . . 1 . . . 1 .

1 1 1 1 1 1 1 1 1 .

1 1 1 1 1 1 1 1 1 1

;

%macro multi;

%do i=1 %to 10;

data table&i(drop=count);

set test;

if count=&i;

run;

%end;

%mend;

%multi;

art297
Opal | Level 21

A couple of solutions can be found at:

Alternatively, if you have SAS/STAT, you can probably use proc plan to accomplish the task.

Rick_SAS
SAS Super FREQ

PROC PLAN is in SAS/STAT software.

art297
Opal | Level 21

Thanks Rick!  After seeing your note I corrected it on my original post.

Art

data_null__
Jade | Level 19

Does this example model your data and desired output?  I do not understand exactly the starting point.

data bvars;
   do id=1 to 300;
     
array v[10];
      do _n_ = 1 to dim(v);
         v[_n_] = rantbl(4,.5)-1;
        
end;
     
output;
     
end;
  
run;
proc summary data=bvars chartype;
  
class v:;
   ways 2;
  
output out=ways2;
   run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 6291 views
  • 0 likes
  • 5 in conversation