BookmarkSubscribeRSS Feed
ajb
Obsidian | Level 7 ajb
Obsidian | Level 7

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?

1 REPLY 1
andreas_lds
Jade | Level 19

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.

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!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 582 views
  • 0 likes
  • 2 in conversation