BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MUKASADAVID
Calcite | Level 5

Hello Community,

I want to create a variable containing the days each person was followed up in the study using one date as the reference start date/study commencement date. There is a variable in my data set which has dates on which the participants were examined first and dates for the follow up examinations. The variable which has the dates on which measurements were taken has dates entered in format like this "20050101" which represents the year=2005, month=january and day=1st day of the month.
The data has five years of follow up but each person entered the study at different dates and different numbers of hospital visits.

I want to create a variable having number of days each person was followed up and for each visit.

 

data finished;
input id Date diagnosis @;
datalines;
1 20050101  0
1 20050502  0
1 20070708  0
1 20090306  0
2 20070608  0
2 20090502  1
2 20090805  1
2 20090703  1
2 20100507  0
3 20050101  0
3 20050502  0
3 20070708  0
3 20090306  0
3 20070608  0
4 20060502  1
4 20090205  0
4 20090403  1
4 20100907  0

 

how can i create a time variable in days for these repeated measurements? 

 

I have tried different codes but they dont give the correct days followed up which I need for conducting a survival analysis.

will be glad to be assisted.

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Your original post stated that your field was called "date". Apparently, that isn't what your date field is actually called. The next question is whether it was originally processed the way you described. If so, the following would work:

data finished;
  input id RECU_FR_DT diagnosis @;
  datalines;
1 20050101  0
1 20050502  0
1 20070708  0
1 20090306  0
2 20070608  0
2 20090502  1
2 20090805  1
2 20090703  1
2 20100507  0
3 20050101  0
3 20050502  0
3 20070708  0
3 20090306  0
3 20070608  0
4 20060502  1
4 20090205  0
4 20090403  1
4 20100907  0
;

data want;
  set finished;
  RECU_FR_DT=input(put(RECU_FR_DT,8.),yymmdd8.);
  format RECU_FR_DT date9.;
run;

Art, CEO, AnalystFinder.com

View solution in original post

4 REPLIES 4
art297
Opal | Level 21

Convert your dates into SAS dates. That way you can subtract any two dates to get the number of days elapsed. e.g.:

data want;
  set finished;
  date=input(put(date,8.),yymmdd8.);
  format date date9.;
run;

Art, CEO, AnalystFinder.com

 

MUKASADAVID
Calcite | Level 5

Hello my advisor;

 

I tried to run the code you gave me and it ran successfully but the created date variable named "date" has no contents.

 

How can i successfully run it again and get the date contents converted and moved to this new variable?. 

 

FOR EXAMPLE;

 

My data set named finished, has a variable "RECU_FR_DT"  and it is this variable that has dates for each observations. I want to have these dates into sas date format(Variable) and then apply general calculation for all participants to get the days they were followed up in the study but I havent suceeded yet.

 

 

Thank you very much for the response.

I will be glad again to be assisted.

 

art297
Opal | Level 21

Your original post stated that your field was called "date". Apparently, that isn't what your date field is actually called. The next question is whether it was originally processed the way you described. If so, the following would work:

data finished;
  input id RECU_FR_DT diagnosis @;
  datalines;
1 20050101  0
1 20050502  0
1 20070708  0
1 20090306  0
2 20070608  0
2 20090502  1
2 20090805  1
2 20090703  1
2 20100507  0
3 20050101  0
3 20050502  0
3 20070708  0
3 20090306  0
3 20070608  0
4 20060502  1
4 20090205  0
4 20090403  1
4 20100907  0
;

data want;
  set finished;
  RECU_FR_DT=input(put(RECU_FR_DT,8.),yymmdd8.);
  format RECU_FR_DT date9.;
run;

Art, CEO, AnalystFinder.com

MUKASADAVID
Calcite | Level 5

Hello my advisor;

 

1. First request:

 

I tried the second code you  recommended to me in the last message but it didn't solve the problelm. The system returned the error below, 

 

"The format $date was not found or could not be loaded"

 

This variable when I run proc contents to see its attributes , it shows that type (charcter variable) with a lenght of 8. 

 

The second issue assistance  in the data i presented in my original post as seen below'

 

 

2. Second request;

 

I wish also to create a variable with patients who have been positively diagnosed more than 3 times as the true POSITIVE result ( to be coded as 1)  and the rest { combine those with less than 3 times of positive diagnosis + Those with negaive diagnosis(o) as Truly NEGATIVE result.

 

That is to say some one with positive diagnosis only twice or less to be considered as [HEALTH coded as 0} and those with more than 3 times of postive diagnosis as Truly {SICK coded as 1}. This data is longitudinal with many repaeted observations on different dates and i want to retain all information of the patients but group them as diseases and health according to the above criteria to conduct survival analysis.

 

I will be glad to recieve more advise about those two problems above. 

 

 

Thank you very uch for the continued assistance.

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1329 views
  • 0 likes
  • 2 in conversation