Help using Base SAS procedures

Create study day variable for multiple per day encounters

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

Create study day variable for multiple per day encounters

Hi,

I am trying to create a study day variable for patients that have multiple encounters per day.

For example:

ID    Date        Study Day (want to create this)

12   6/20/14      1

12   6/20/14      1

12   6/20/14      1

12   6/20/14      1

12   6/22/14      2

12   6/26/14      3

13   6/20/14      1

Any thoughts?

Thanks!


Accepted Solutions
Solution
‎08-07-2015 12:54 AM
Regular Contributor
Posts: 217

Re: Create study day variable for multiple per day encounters

Hi, perhaps you could try this?

data have;

input ID DATE MMDDYY10.;

datalines;

12   6/20/14

12   6/20/14

12   6/20/14

12   6/20/14

12   6/22/14

12   6/26/14

13   6/20/14

;

run;

proc sort data=have; by ID Date; run;

data want;

  set have;

  by ID Date;

  if first.id then studyday=.;

  if not missing(date) then do;

  if date ne lag(date) then studyday+1;

  end;

run;

proc print noobs; format date ddmmyy10.; run;

View solution in original post


All Replies
Solution
‎08-07-2015 12:54 AM
Regular Contributor
Posts: 217

Re: Create study day variable for multiple per day encounters

Hi, perhaps you could try this?

data have;

input ID DATE MMDDYY10.;

datalines;

12   6/20/14

12   6/20/14

12   6/20/14

12   6/20/14

12   6/22/14

12   6/26/14

13   6/20/14

;

run;

proc sort data=have; by ID Date; run;

data want;

  set have;

  by ID Date;

  if first.id then studyday=.;

  if not missing(date) then do;

  if date ne lag(date) then studyday+1;

  end;

run;

proc print noobs; format date ddmmyy10.; run;

Super User
Posts: 17,829

Re: Create study day variable for multiple per day encounters

Data want;

set have;

by id date;

retain studyday;

if first.id the studyday=0;

if first.date then studyday+1;

run;

Occasional Contributor
Posts: 9

Re: Create study day variable for multiple per day encounters

Thank you both so much! The solutions worked perfectly!

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 341 views
  • 6 likes
  • 3 in conversation