Community talk about communities.sas.com. Meta!

How can I create a variable for number of days spend in the study using the dates of examination

Reply
New Contributor
Posts: 4

How can I create a variable for number of days spend in the study using the dates of examination


 

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.

PROC Star
Posts: 7,360

Re: How can I create a variable for number of days spend in the study using the dates of examination

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

Ask a Question
Discussion stats
  • 1 reply
  • 182 views
  • 0 likes
  • 2 in conversation