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!
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;
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;
Data want;
set have;
by id date;
retain studyday;
if first.id the studyday=0;
if first.date then studyday+1;
run;
Thank you both so much! The solutions worked perfectly!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.