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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Fugue
Quartz | Level 8

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

3 REPLIES 3
Fugue
Quartz | Level 8

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;

rrevans
Calcite | Level 5

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

Tom
Super User Tom
Super User

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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