BookmarkSubscribeRSS Feed
kqmq
Calcite | Level 5

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.

2 REPLIES 2
Reeza
Super User

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.


 

ballardw
Super User

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.;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 2 replies
  • 619 views
  • 0 likes
  • 3 in conversation