Hi,
I am currently learning proc sql and I am trying to figure out how to code a 6 month look back period for EVENT. In my data set everyone has had EVENT. I would like to look back 6 months pre EVENT to determine if anyone in my data set filled a prescription for DRUG. I created a flag for whether or not a person has ever filled a prescription (1=yes, 0=no) and I also have the date of drug fill. An example of some of the variables in the the data set is presented in the table below.
How do I create a table with only people who filled the drug in the 6 month look back period?
ID | EVENT_DATE | DRUG 1/0 | Drug_fill_date |
2 | 2/5/00 | 1 | 3/12/99 |
2 | 2/5/00 | 1 | 4/11/99 |
2 | 2/5/00 | 1 | 30/09/99 |
3 | 3/2/04 | 1 | 3/1/04 |
3 | 3/2/04 | 1 | 3/12/03 |
4 | 4/3/09 | 0 | |
5 | 3/5/08 | 1 | 5/9/07 |
6 | 4/3/11 | 0 |
This is a bare bones version of the code I ran using proc sql
data eg1;
set eg1;
(where=(start = ('event_date'-180) and end ='event_date'));
run;
proc sql;
create table eg2 as
select * from eg1
where start<= Drug_fill_date<= end
;
quit;
Can you please help me to figure out where I have gone wrong in this code?
Posting data in usable form is always a good idea to get more helpful answers than this one 😉
The variables "event_date" and "drug_fill_date" are sas-dates, right?
You are using the variables "start" and "end" - i can't see them in the table you posted.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.