BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SAS_Novice22
Quartz | Level 8

Morning SAS Experts,

 

I am wondering if anyone would be willing to to guide me towards the correct steps to take. What I would like to do is look only at users who took Drug A after enrollment (I do not have a specific variable for this) but I do have a list of all subject ID numbers of those who have taken Drug A after enrollment.
Essentially, I would like to use these subject numbers (N=15) in order to conduct separate analyses on this group of individuals only.

 

I am not sure if I should generate new variable or use a series of if or then statements or if there is another way to do this.

 

Any recommendations would be greatly appreciated.

 

Thank you,

T.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Just add a WHERE statement to your analysis, you can use the IN operator to test if the value in one of a list of values.

So if the subject id numbers are in the character variable ID (why would an identifier by a numeric variable) then you just need something like:

proc means data=have ;
  where id in ('101','203','405');
   var age ht wt;
run;

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

You could probably type the ID numbers in, but I suspect that these 15 IDs are already in some text file or spreadsheet or database or other electronic form. If that's the case, then read the text file or spreadsheet or database table and use that information to help you segregate the data to do the analysis you want.

--
Paige Miller
Tom
Super User Tom
Super User

Just add a WHERE statement to your analysis, you can use the IN operator to test if the value in one of a list of values.

So if the subject id numbers are in the character variable ID (why would an identifier by a numeric variable) then you just need something like:

proc means data=have ;
  where id in ('101','203','405');
   var age ht wt;
run;
SAS_Novice22
Quartz | Level 8

This did the trick - thank you very much. I just modified it to be for Tables/frequency as opposed to means.

Thanks again.

T.

Reeza
Super User

Assumptions:

  • Input data set with all participants is called HAVE
  • data set with list of 15 IDs who need to be included are in dataset called SELECTED
proc sql;
create table want as
select * from have
where ID in (Select ID from SELECTED);
quit;

This works regardless if ID's are duplicated in the HAVE or SELECTED cases. 

 

If IDs are not duplicated in any data set another method is:

proc sort data=have;
by ID;
proc sort data=selected;
by ID;

data want;
merge have selected(in=sel);
by ID;
if sel;
run;

@SAS_Novice22 wrote:

Morning SAS Experts,

 

I am wondering if anyone would be willing to to guide me towards the correct steps to take. What I would like to do is look only at users who took Drug A after enrollment (I do not have a specific variable for this) but I do have a list of all subject ID numbers of those who have taken Drug A after enrollment.
Essentially, I would like to use these subject numbers (N=15) in order to conduct separate analyses on this group of individuals only.

 

I am not sure if I should generate new variable or use a series of if or then statements or if there is another way to do this.

 

Any recommendations would be greatly appreciated.

 

Thank you,

T.


 

SAS_Novice22
Quartz | Level 8
Hi @Reeza,
I am sure this would also work. I need to build up my skill at reading and writing code for now I went with Tom's simple code above however, I do plan to try this code out shortly.
Thank you again.
T.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 610 views
  • 3 likes
  • 4 in conversation