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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Miracle
Barite | Level 11

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

3 REPLIES 3
Miracle
Barite | Level 11

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;

Reeza
Super User

Data want;

set have;

by id date;

retain studyday;

if first.id the studyday=0;

if first.date then studyday+1;

run;

he2182
Calcite | Level 5

Thank you both so much! The solutions worked perfectly!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1136 views
  • 6 likes
  • 3 in conversation