Hi, I wondered if someone could help with a question I have regarding some SAS code I am trying to figure out below:

Accepted Solution Solved
Reply
Contributor
Posts: 57
Accepted Solution

Hi, I wondered if someone could help with a question I have regarding some SAS code I am trying to figure out below:

I am trying to "paramaterize" a  time frame in my code. So, in the program now it is hard coded to look for the comorbid events  to occur within 365 days prior to the diagnosis date, but it should take that 365 days as an input. Better yet, it would be nice if it could look for the comorbid events  at any time (say within 90 days AFTER index).   Not sure how to do this can anyone help?  Many thanks Lisa.


Accepted Solutions
Solution
‎02-18-2014 08:18 AM
Frequent Contributor
Posts: 83

Re: Hi, I wondered if someone could help with a question I have regarding some SAS code I am trying to figure out below:

Sort of, the way that you have it written is that early would actually occur after late (ie 365 days after index is greater than 90), I think you actually wanted to write -365 as the lookback, but that is just my guess. Also you didn't specify a then statement after your if, so the program would likely result in an error because it didn't follow logic. My guess is that you are asking for only those records so you could write is as a where statement. My preference is to write a where statement without an AND but either way will work. The other thing that might be useful is to flag the records that were before and after, this change is suggested in green below. The changes I would suggest without this flagging are below in red. One last thing I can't remember in data step if where is supposed to come first, last, or anywhere in between so if you use the green changes you may have to play around with the location of the where statement to get it to run.

%let earlyv =-365;

%let latev =90;

%macro comorbid (early = , late = );

data diag;

  set index.diagnosis_file;

where &early <= datdif(indexdate,codedate,'act/act') <= &late;

if &early <= datdif(indexdate,codedate,'act/act') <= 0 then before = 1;

else before = 0;

if 0 < datdif(indexdate,codedate,'act/act') <= &late then after = 1;

else after = 0;

run;

%mend;

%comorbid(early=&earlyv, late=&latev);

Hope this helps.

View solution in original post


All Replies
Contributor
Posts: 74

Re: Hi, I wondered if someone could help with a question I have regarding some SAS code I am trying to figure out below:

if intck("days",diagnosis_dat,date() ) < 365 then "Your condistion";

Contributor
Posts: 57

Re: Hi, I wondered if someone could help with a question I have regarding some SAS code I am trying to figure out below:

Thank you for your answer.  Do you know a way if it could look for the conditions at any time (say within 90 days AFTER index).

Contributor
Posts: 57

Re: Hi, I wondered if someone could help with a question I have regarding some SAS code I am trying to figure out below:

This is my current code 

if a and b and ((IndexDate - 365) <= CodeDate < IndexDate);

I really want to be able to put any number in this program i.e substitute 365 with 5, 10, 20. 90 etc depending on the inclusion criteria from a given protocol.  Is there anyway the user running this program can be prompted to enter this value?

Super User
Super User
Posts: 6,497

Re: Hi, I wondered if someone could help with a question I have regarding some SAS code I am trying to figure out below:

Use macro variables to allow this type of flexibility.

%let interval=365 ;

....

if a and b and ((IndexDate - &interval ) <= CodeDate < IndexDate);

....


Once you get that working you might consider converting the program to a macro.


%macro comorbid(interval) ;

   ....

%mend comorbid;


Then users could call it with the interval they want:

%comorbid(interval=360)




Frequent Contributor
Posts: 83

Re: Hi, I wondered if someone could help with a question I have regarding some SAS code I am trying to figure out below:

Essentially it sounds like you are trying to figure out how to vary your look-back period and then likely use the same code to determine outcomes. So the easiest way may be to specify the code in a macro as Tom suggested, but give yourself a start and end time, ie 365 to 1 day before Index, or 1 day to 90 days post index. The real question though will be if you want to keep all of the records, or only those that have the comorbid within the time period.

Your current code is if a and b and ((IndexDate - 365) <= CodeDate < IndexDate); which does not allow for much specification, but if you rewrote it to

%macro comorbid (early = , late = );

Code...

if datdif(indexdate,codedate,'act/act') between &early and &late

More code...

%mend;

For 365 to 0 days before

%comorbid(early=-365,late=0);

For 1 to

days post

%comorbid(early=1,late=90);

OR if you want the user to actually think about what they are entering in, you could put it outside of the macro in a let statement, ie

%let earlyv =

%let latev =

(enter the values into the these statements)

then the macro call could be written like this.

%comorbid(early=&earlyv, late=&latev);

I tend to use let statements if all of the code will be using similar structures, or if I want to be sure of what I am coding at the very beginning rather than, when I get to it in the code.

Hope this helps

Contributor
Posts: 57

Re: Hi, I wondered if someone could help with a question I have regarding some SAS code I am trying to figure out below:

Than you so much.  I will have access to data later to test program but just wondered if what I have below is correct from your above message -  do you think something like this will work:? Thanks you so much again.

%let earlyv =365;

%let latev =90;

%macro comorbid (early = , late = );

data diag;

  set index.diagnosis_file;

if datdif(indexdate,codedate,'act/act') < &early and datdif(indexdate,codedate,'act/act') > &late;

run;

%mend;

%comorbid(early=&earlyv, late=&latev);

Solution
‎02-18-2014 08:18 AM
Frequent Contributor
Posts: 83

Re: Hi, I wondered if someone could help with a question I have regarding some SAS code I am trying to figure out below:

Sort of, the way that you have it written is that early would actually occur after late (ie 365 days after index is greater than 90), I think you actually wanted to write -365 as the lookback, but that is just my guess. Also you didn't specify a then statement after your if, so the program would likely result in an error because it didn't follow logic. My guess is that you are asking for only those records so you could write is as a where statement. My preference is to write a where statement without an AND but either way will work. The other thing that might be useful is to flag the records that were before and after, this change is suggested in green below. The changes I would suggest without this flagging are below in red. One last thing I can't remember in data step if where is supposed to come first, last, or anywhere in between so if you use the green changes you may have to play around with the location of the where statement to get it to run.

%let earlyv =-365;

%let latev =90;

%macro comorbid (early = , late = );

data diag;

  set index.diagnosis_file;

where &early <= datdif(indexdate,codedate,'act/act') <= &late;

if &early <= datdif(indexdate,codedate,'act/act') <= 0 then before = 1;

else before = 0;

if 0 < datdif(indexdate,codedate,'act/act') <= &late then after = 1;

else after = 0;

run;

%mend;

%comorbid(early=&earlyv, late=&latev);

Hope this helps.

Contributor
Posts: 57

Re: Hi, I wondered if someone could help with a question I have regarding some SAS code I am trying to figure out below:

Thank you so much for your time and expertise... I will give it a go.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 317 views
  • 0 likes
  • 4 in conversation