+ Reply to Thread
Results 1 to 3 of 3

Thread: Exclusion Criteria

  1. #1
    Points: 9,065, Level: 64
    Level completed: 5%, Points required for next Level: 285

    Posts
    482
    Thanks
    22
    Thanked 3 Times in 3 Posts

    Exclusion Criteria



    Hi,

    I have data that has the following lay out:

    Code: 
    Teacher  Student   Service   Date
    smith     john       tutoring   mar312005
    smith     john       reading    mar312005
    smith     john       spelling    mar312005
    smith     sally       tutoring    mar312005
    smith     sarah      reading   mar312005
    What I'd like to do is exclude a students entire case if they have a specific service requested. For example, my criteria of exclusion is reading. Therefore, I'd like to remove the reading entries for both students John and Sarah. however, John as you can see had two additional services provided on the same date (tutoring and spelling). I'd also like to remove these two entries as they are associated with the exclusion criteria.

    The data are in long format. Teachers can see more than 1 student a day. A student can request more than 1 service in a visit. Again, I'd like to remove the students entire entry for that specific date / teacher combination if they had the exclusion critera.

    any tips?

    best,

    edit: i've started by identifying my exclusion critera. I've output to a separate dataset all entries of the exlcusion criteria. I now have to do some kind of a careful merge back with the original dataset to exclude the entries that are not exlcusion criteria directly, but were associated with it (i.e, same student, same teacher and same date, different service)
    Last edited by jamesmartinn; 07-16-2012 at 08:56 AM. Reason: showing work

  2. #2
    TS Contributor
    Points: 6,942, Level: 54
    Level completed: 96%, Points required for next Level: 8

    Posts
    782
    Thanks
    0
    Thanked 71 Times in 70 Posts

    Re: Exclusion Criteria

    I've found this is real easy once you stop trying to be elegant, and just use two data steps.
    Code: 
    *Identify the teacher/date records to eliminate: associated with reading;
    data eliminates;
      set yourdata;
      if upcase(service)="READING";
      keep teacher student date;
    run;
    
    *Reduce YOURDATA set;
    proc sort data=yourdata; by teacher student date; run;
    proc sort data=eliminates nodupkey; by teacher student date; run;
    
    data yournewdata;
      merge yourdata(in=a) eliminates(in=b);
      by teacher student date;
      if (not b);
    run;
    Alternatively, if you already have a dataset with exclusions that are more complicated than just service="reading", you can make the eliminates dataset like
    Code: 
    data eliminates;
      merge yourdata(in=a) exclusions(in=b);
      by service;
      if a and b;
      keep teacher student date;
    run;
    I've done stuff like this before using retain statements, delete flags, and sorting...but it's really simple like this.

  3. The Following User Says Thank You to Mean Joe For This Useful Post:

    jamesmartinn (07-18-2012)

  4. #3
    Points: 9,065, Level: 64
    Level completed: 5%, Points required for next Level: 285

    Posts
    482
    Thanks
    22
    Thanked 3 Times in 3 Posts

    Re: Exclusion Criteria


    Thanks Joe!

    You are absolutely right. I did try to be fancy (or efficient) in my coding and I think it really inhibited my progress. I started from scractch and went the datastep route using a contrived dataset. I was able to get the results I needed and our code is very similar!

    Thank you so much for the reply - it is much appreciated!

    Cheers,

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts








Advertise on Talk Stats