Using Multiple Where Statements

2019-08-27 09:14发布

问题:

I'm attempting to filter out records that contain specific words within a string for the REASON_FOR_VISIT variable. I then want to use the remaining records to compute the median values for the variable total_ed_los and arrive_to_dr_sees.

I have the following code but I'm afraid that it's not filtering out the strings I would like it to. Is this an instance I need to use PROC SQL or are there other options?

Thanks!

data FT_Post;
set WORK.FT_May;
Where checkin_time between '12:00't and '20:00't;
Where REASON_FOR_VISIT Not Like '%psyc%';
Where REASON_FOR_VISIT Not Like '%psy eval%';
Where REASON_FOR_VISIT Not Like '%psych%';
Where REASON_FOR_VISIT Not Like '%suicid%';
Where REASON_FOR_VISIT Not Like '%homicid%'; 
run; 

proc means data=FT_Post median;
class checkin_date;
var  total_ed_los arrive_to_dr_sees;
run;

回答1:

If you have multiple 'vanilla' where clauses in a datastep you will see the following in the log:

NOTE: WHERE clause has been replaced.

To avoid this behaviour, you can use where also:

data FT_Post;
set WORK.FT_May;
Where checkin_time between '12:00't and '20:00't;
Where also REASON_FOR_VISIT Not Like '%psyc%';
Where also REASON_FOR_VISIT Not Like '%psy eval%';
Where also REASON_FOR_VISIT Not Like '%psych%';
Where also REASON_FOR_VISIT Not Like '%suicid%';
Where also REASON_FOR_VISIT Not Like '%homicid%'; 
run; 

You will now see:

NOTE: WHERE clause has been augmented.



标签: sas