Help using Base SAS procedures

Assigning treatment groups

Accepted Solution Solved
Reply
Contributor
Posts: 20
Accepted Solution

Assigning treatment groups

Hi,

I am trying to assign treatments of "_drug_of_interest_" and "_not drug of interest_" to my data set. I have one data set of "drug data" where I can assign an indicator variable of "drug" and "not drug." This needs to be merged with my data set of "clinical data" where I can then separate all data I have on those ids into treatment groups.

This is what I've tried so far:

I assigned my indicator variable of 1's and 0's to my drug data set and merged that with the clinical data then subset the data by that indicator variable. When I subset the data I get the correct number of ids assigned to my drug of interest data set (I know this number), the control group though turns out to be all the ids in the list because they were treated with multiple drugs. Below is a sample:

iddrugindicator
1A1
1B0
2B0
2B0
2C0

Assume A is my drug of interest. I would like to make a list of all ids that received drug A and a list of all ids that did not receive A. If an id can have a 1 as an indicator I would like to take out all data rows belonging to that patient and place them into a separate list, that way there is no overlap in patients.

Am I posting in the right community? Is more information necessary? Any suggestions?

Thank You.


Accepted Solutions
Solution
‎09-09-2013 02:40 PM
Super Contributor
Posts: 307

Re: Assigning treatment groups

Proc sql;

     create table drugAlist as

     select distinct id

     from have

     where indicator = 1

;

quit;

Proc sql;

     create table notdrugAlist as

     select distinct id

     from have

     where id not in

          ( select id

          from drugAlist )

;

quit;

View solution in original post


All Replies
Solution
‎09-09-2013 02:40 PM
Super Contributor
Posts: 307

Re: Assigning treatment groups

Proc sql;

     create table drugAlist as

     select distinct id

     from have

     where indicator = 1

;

quit;

Proc sql;

     create table notdrugAlist as

     select distinct id

     from have

     where id not in

          ( select id

          from drugAlist )

;

quit;

Contributor
Posts: 20

Re: Assigning treatment groups

Thank you for this. I did not think this would work as well as it did. I did have to merge this list back to the original once I had the flags in place to gather all the data in one list. I tried both methods given here by yourself and Tom and both achieve the same result.

Thanks again

Super User
Super User
Posts: 6,502

Re: Assigning treatment groups

So you want to create a patient level flag?

data have ;

  input id drug $ old_flag;

cards;

1 A 1

1 B 0

2 B 0

2 B 0

2 C 0

run;

data want ;

  do until (last.id);

     set have ;

     by id ;

     if drug in ("A") then new_flag = 1;

  end;

  new_flag = coalesce(new_flag,0);

  keep id new_flag ;

run;

data _null_;

  set;

  put (id new_flag) (=) ;

run;

id=1 new_flag=1

id=2 new_flag=0

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 188 views
  • 3 likes
  • 3 in conversation