DATA Step, Macro, Functions and more

Detect Recurrent Disease

Reply
Occasional Learner
Posts: 1

Detect Recurrent Disease

[ Edited ]

I am trying to write code to read recurrent diseases in a database.  I already successfully wrote code for comorbidity in the database.  However I cannot get the code that I have written below to work.

 

data kevinrecurrent;

set testtreat;

length recurrent $150;

 

recurrent = cat(lastname, firstname, dob_mo, dob_day, dob_yr, diagnosisdate);

newrecurr=.;

if newrecurr ge 14 and newrecurr le 60;

 

I am attempting to create a variable (recurrent) which reads the firstname, lastname, date of birth and diagnosis date for the patient.

I am also attempting to establish that recurrent cases are those between 2 weeks and 60 days after the first treatment

how do I do this? I am stuck at above.

Super User
Posts: 23,296

Re: writing code for sas

I am attempting to create a variable (recurrent) which reads the firstname, lastname, date of birth and diagnosis date for the patient.

 

I don't know what that means. Can you please show an example, using fake data?

What are you expecting to happen with the CAT() function - which concatenates variables. 

 


@kqmq wrote:

I am trying to write code to read recurrent diseases in a database.  I already successfully wrote code for comorbidity in the database.  However I cannot get the code that I have written below to work.

 

data kevinrecurrent;

set testtreat;

length recurrent $150;

 

recurrent = cat(lastname, firstname, dob_mo, dob_day, dob_yr, diagnosisdate);

newrecurr=.;

if newrecurr ge 14 and newrecurr le 60;

 

I am attempting to create a variable (recurrent) which reads the firstname, lastname, date of birth and diagnosis date for the patient.

I am also attempting to establish that recurrent cases are those between 2 weeks and 60 days after the first treatment

how do I do this? I am stuck at above.


 

Super User
Posts: 13,321

Re: Detect Recurrent Disease

This code is very suspect as to what you might be attempting.

newrecurr=.;

if newrecurr ge 14 and newrecurr le 60;

The first line sets a missing value to a variable. Then you attempt to only keep records where the value is between 14 and 60.

 

 

The approach looks like you should sort your data by lastname, firstname, dob_mo, dob_day, dob_yr, and diagnosisdate.

Then you can use Retain and or first and last processing to see if a person has more than one diagnosis.

I suspect you may be missing a detail or two such as which variable has the actual disease diagnosis (which should go before diagnosisdate in the sort order).

 

Here is an example of retaining a value from previous records and using it later for a comparison

proc sort data=sashelp.class out=work.class;
  by sex age;
run;

data work.example;
   set work.class;
   by sex age;
   retain firstageweight firstageheight;
   if first.age then do;
      firstageweight=weight;
      firstageheight=height;
   end;
   diffageweight = weight - firstageweight;
   diffageheight = height - firstageheight;
run;

Also is your diagnosisdate an actual SAS date valued numeric or something else? Date comparisons work much better with data values.

 

You also might want to consider generating and actual DOB date value with :

Dobdate = mdy(dob_mo, dob_day, dob_yr);

format dobdate date9.;

Ask a Question
Discussion stats
  • 2 replies
  • 80 views
  • 0 likes
  • 3 in conversation