DATA Step, Macro, Functions and more

Labeling index date for each patient

Accepted Solution Solved
Reply
Contributor
Posts: 44
Accepted Solution

Labeling index date for each patient

Hi all, 

 

With the following code I'm trying to 

 

1) Compile all the inpatient claims files from 2010 - 2014;

2) Subset to only those with the right dx1 codes, right age, and then label which one is the "index claim". Eventually I want to just have those who are continuously enrolled +/- 1 year before and after index date.

 

The following code does not seem to work -- wondering what I should tweak? 

 

/*Input codes*/ 
%let dx1_list = '123', '12345';
%let age_cutoff = 18;

		/*0.1.0 SETUP LIBS */

		libname raw "Z:\" ACCESS = READONLY;

		/*0.1.1 GENERATE LIST OF PTS WITH ANY CLAIMS*/

		data compiled_ip;
			set raw.ccaes103 raw.ccaes113 raw.ccaes122 raw.ccaes132; 
		run;

		data compiled_ip_index;
			set compiled_ip;
			where dx1 in (&dx1_list.) and age >= &age_cutoff.;
			by enrolid svcdate;
			if first.enrolid then do;
				index_dt=svcdate;
				end;
		run;

Accepted Solutions
Solution
‎12-26-2017 06:22 PM
Esteemed Advisor
Posts: 5,129

Re: Labeling index date for each patient

[ Edited ]

If what you want is to have index_dt defined for every observation, you should do:

 

data compiled_ip_index;
do until(last.enrolid);
    set compiled_ip;
    where dx1 in (&dx1_list.) and age >= &age_cutoff.;
    by enrolid svcdate;
    if first.enrolid then index_dt = svcdate;
    end;
run;

 

PG

View solution in original post


All Replies
PROC Star
Posts: 7,801

Re: Labeling index date for each patient

[ Edited ]

What did you log show? My initial guess is that you need to sort the file compiled_ip, by enrolid svcdate, prior to running the final datastep.

 

Art, CEO, AnalystFinder.com

 

Contributor
Posts: 44

Re: Labeling index date for each patient

Ahh thanks! That is it! Need to sort before... 

 

Now what I have is index_date showing up as 18744 which doesn't appear to be in the MMDDYYYY format. 

 

1) Any idea how I can get this date to show up in the right format?

2) Currently index_date is showing up only for the first.enroll_id (which is what I want) -- how do I apply that index_date for all subsequent claims with the same enrollid?

 

 

Trusted Advisor
Posts: 1,149

Re: Labeling index date for each patient

What do you mean by "not work"?  What results did you expect, and what results did you get?

Solution
‎12-26-2017 06:22 PM
Esteemed Advisor
Posts: 5,129

Re: Labeling index date for each patient

[ Edited ]

If what you want is to have index_dt defined for every observation, you should do:

 

data compiled_ip_index;
do until(last.enrolid);
    set compiled_ip;
    where dx1 in (&dx1_list.) and age >= &age_cutoff.;
    by enrolid svcdate;
    if first.enrolid then index_dt = svcdate;
    end;
run;

 

PG
Contributor
Posts: 44

Re: Labeling index date for each patient

Thank you so much! Read my mind! 

 

My index_dt is currently showing up as 18744... or something that is unlike MMDDYYYY. Any idea how I can make it in the same format as the svc_dt? which is currently like 11/22/2014 or something. 

Esteemed Advisor
Posts: 5,129

Re: Labeling index date for each patient

Add the statement

 

format index_dt mmddyys10.;

 

to your data step.

PG
Contributor
Posts: 44

Re: Labeling index date for each patient

I know that this is an old post, but I'm revisiting this code and it seems like the output just has the first enrolid observation and none of the following. Wondering if there is a way to get around this?

Esteemed Advisor
Posts: 5,129

Re: Labeling index date for each patient

Try

 

data compiled_ip_index;
do until(last.enrolid);
    set compiled_ip;
    where dx1 in (&dx1_list.) and age >= &age_cutoff.;
    by enrolid svcdate;
    if first.enrolid then index_dt = svcdate;
    output;
    end;
format index_dt mmddyys10.;
run;

(untested)

 

PG
Contributor
Posts: 44

Re: Labeling index date for each patient

This works!! Thank you! 

PROC Star
Posts: 7,801

Re: Labeling index date for each patient

Not sure which post your various comments are responding to. To keep the value for all records simply use a retain statement:

		data compiled_ip_index;
			set compiled_ip;
                        retain index_dt.;
			where dx1 in (&dx1_list.) and age >= &age_cutoff.;
			by enrolid svcdate;
			if first.enrolid then do;
				index_dt=svcdate;
				end;
		run;

As for the format, like @PGStats suggested, simply add a format statement.

 

Art, CEO, AnalystFinder.com

 

Contributor
Posts: 44

Re: Labeling index date for each patient

Apologies for the confusion. 

 

Would the "retain" statement populate the index_dt value only for that specific enrolid? 

 

Also, your post would count as a solution as well! Is there a way I can select two posts as a solution? 

 

Thank you so much! 

PROC Star
Posts: 7,801

Re: Labeling index date for each patient

I don't care which post you mark as a solution .. that is totally up to you. You can read about the retain statement at: http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000214163.htm

 

Art, CEO, AnalystFinder.com

Highlighted
New User
Posts: 1

Re: Labeling index date for each patient

Hey cdubs,

 

The code identifies the index date. I am curious about how did you achieve the next step of finding who are continuously enrolled +/- 1 year before and after index date.

 

Thanks!

☑ This topic is solved.

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

Discussion stats
  • 13 replies
  • 254 views
  • 6 likes
  • 5 in conversation