DATA Step, Macro, Functions and more

number of days in the study period

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 142
Accepted Solution

number of days in the study period

Hi! I need help calculating the number of actual days a person was in my 5 year study.  So, looking accross observations, I need to calculate number of days between the first encounter date 'encdate' and last encounter date by 'patientid'.

 

Assistance is apprecited!

 


Accepted Solutions
Solution
‎06-08-2016 10:21 AM
Super User
Posts: 5,497

Re: number of days in the study period

Here's one approach.

 

proc summary data=have nway;

class patientid;

var encdate;

output out=durations (keep=patientid firstday lastday) min=firstday max=lastday;

run;

 

This gives you a data set with three variables in it, and one observation per patientid.  You can use that in a DATA step, and apply whichever formula you wish:

 

duration = lastday - firstday;

duration = lastday - firstday + 1;

 

The SQL programmers out there can do this in one step, but SQL isn't my strong point.

View solution in original post


All Replies
Super User
Posts: 19,770

Re: number of days in the study period

Please post sample input and output data.

Solution
‎06-08-2016 10:21 AM
Super User
Posts: 5,497

Re: number of days in the study period

Here's one approach.

 

proc summary data=have nway;

class patientid;

var encdate;

output out=durations (keep=patientid firstday lastday) min=firstday max=lastday;

run;

 

This gives you a data set with three variables in it, and one observation per patientid.  You can use that in a DATA step, and apply whichever formula you wish:

 

duration = lastday - firstday;

duration = lastday - firstday + 1;

 

The SQL programmers out there can do this in one step, but SQL isn't my strong point.

Super User
Posts: 11,343

Re: number of days in the study period

Posted in reply to Astounding

Minor change to @Astounding solution:

 

output out=durations (keep=patientid firstday lastday) range=;

 

Range will basically do the max-min.

New Contributor
Posts: 2

Re: number of days in the study period

how can i get sas software

New Contributor
Posts: 2

Re: number of days in the study period

Posted in reply to kvemulapalli571
please help me how can i get sas software
Super User
Posts: 19,770

Re: number of days in the study period

[ Edited ]
Posted in reply to kvemulapalli571

@kvemulapalli571

1. Please post your questions in a new discussion rather than in someone else's question

2. Google "SAS University Edition" -> This is a free version of SAS available for learning purposes only. You need a 64bit machine. 

    Or use SAS Academics on Demand -> Independent Learners option. 

☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 269 views
  • 0 likes
  • 5 in conversation