0
votes

I generated propensity scores in SAS to match two unequal groups with replacement. Now I'm trying to create a dataset where there are an equal number of observations for both groups-- ie there should be observations in group b that repeat since that is the smaller group. Below I have synthetic data to demonstrate what I'm trying to get.

Indicator Income  Matchid
1         7       1
1         8       2
1         4       1
0         6       1
0         9       2

And I want it to look like this

Indicator Income  Matchid
1         7       1
1         8       2
1         4       1
0         6       1
0         9       2
0         6       1
1
Please 1) add your input, not only your output 2) show us what you triedDirk Horsten

1 Answers

0
votes

In a view you can create a variable that is a group sequence number amenable to modulus evaluation. In a data step load the two indicator groups into separate hashes and then for each loop over the largest group size, selecting by index modulus group size.

Example:

data have;
input Indicator Income  Matchid;
datalines;
1         7       1
1         8       2
1         4       1
0         6       1
0         9       2
;

data have_v;
  set have;
  by indicator notsorted;
  if first.indicator then group_seq=0; else group_seq+1;
run;


data want;
  if 0 then set have_v;

  declare hash i1 (dataset:'have_v(where=(indicator=1))', ordered:'a');
  i1.defineKey('group_seq');
  i1.defineData(all:'yes');
  i1.defineDone();

  declare hash i0 (dataset:'have_v(where=(indicator=0))', ordered:'a');
  i0.defineKey('group_seq');
  i0.defineData(all:'yes');
  i0.defineDone();

  do index = 0 to max(i0.num_items, i1.num_items)-1;
    group_seq = mod(index,i1.num_items);
    i1.find();
    output;
  end;

  do index = 0 to max(i0.num_items, i1.num_items)-1;
    group_seq = mod(index,i0.num_items);
    i0.find();
    output;
  end;

  stop;

  drop index group_seq;
run;

If the two groups were separated into data sets, you could do similar processing utilizing SET options nobs= and point=