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

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

6 REPLIES 6
Reeza
Super User

Please post sample input and output data.

Astounding
PROC Star

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.

ballardw
Super User

Minor change to @Astounding solution:

 

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

 

Range will basically do the max-min.

kvemulapalli571
Calcite | Level 5

how can i get sas software

kvemulapalli571
Calcite | Level 5
please help me how can i get sas software
Reeza
Super User

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

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!

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
  • 6 replies
  • 1002 views
  • 0 likes
  • 5 in conversation