Hello SAS Community,
I am working on a Medicaid dataset that includes a treatment and a control group. To finalize who will be in my treatment group, I need to determine the patients who had continuous enrollment for at least 9 months into an intervention program. I already reconciled the dataset and removed all the duplicated months and years of their enrollment. My reconciling code worked fine, which was-
data Babies_Clean(drop=prior_: temp_: orig_:);
retain orsid begin end;
format Prior_end Orig_begin Orig_end
temp_beg temp_end begin end yymm10.;
set Mcaid_elig_babies(rename=(begin=Orig_begin
end =Orig_end ));
by orsid Orig_begin Orig_end;
if Orig_begin > Orig_end then delete;
Prior_end = lag(Orig_end);
if first.orsid
then do;
temp_beg = Orig_begin;
temp_end = Orig_end;
Prior_end = .;
end;
else if 0 <= (Orig_begin - Prior_end) <= 1
then do;
temp_end = Orig_end;
end;
else if (Orig_begin - temp_end) > 1
then do;
begin = temp_beg;
end = temp_end;
output;
temp_beg = Orig_begin;
temp_end = Orig_end;
end;
else if temp_beg <= Orig_begin <= temp_end
then do;
if Orig_end > temp_end
then temp_end = Orig_end;
end;
if last.orsid then do;
begin = temp_beg;
if Orig_end > temp_end
then end = Orig_end;
else end = temp_end;
output;
end;
run;
Now I want to write the codes that will indicate the patients who were enrolled for at least 9 months into that program separately from those who were enrolled for less than 9 months. I also want to create a new binary variable that will show this indication [i.e., 1 = eligible (had at least 9 months enrollment), 0 = not eligible).
Please help me with this coding.
Thanks a lot!
Farah
Hello Farah,
This is going to be difficult without a good idea of the structure of the dataset and the record layout. Could you share a couple of rows with some sample data that could help clarifying your question ?
Thanks,
Mathias.
Hello Mathias,
Thanks for your reply. I have attached a screenshot of my main 3 raws here:
I apologize, I have reconciled the dates and deleted the duplicates (i.e., Mar 2009 - July 2017 for the 1st orsid 8760376, instead of keeping it in 2 separate sections). But, unfortunately, my file crashed and I am working on it again.
Let me know if this will help with the code for continuous enrollment that I want. For example, the 1st orsid was enrolled from March 2009 - July 2017 (more than 9 months), so he is eligible for my study. Orsid 8749769 was enrolled from November 2008 - May 2009 (less than 9 months, as we can get from the table), so he won't be eligible. There are thousands of ID's in my dataset, so I can't do them manually. I need a code for that and I also want to create a variable that will indicate 1 = eligible and 0 = not, according to equal or more than 9 months and less than that.
Thanks again!
Farah
Hi Farah,
Are you still looking for a solution ? I think this example here would be a good start:
data have ;
infile cards;
input orsid begin : date9. end : date9.;
format begin end monyy7.;
cards;
8760376 01MAR2009 01JAN2010
8760376 01JAN2010 01JUL2017
8749769 01NOV2008 01APR2009
8749769 01NOV2008 01MAY2009
8749769 01NOV2008 01MAY2009
;
run;
data want;
set have ;
retain prev_begin prev_end;
by notsorted orsid;
if not first.orsid then do;
if begin le prev_end then begin=prev_begin;
end;
length=INTCK('MONTH',begin,end);
prev_begin=begin;
prev_end=end;
format prev_begin prev_end monyy7.;
run;
Here is the resulting dataset:
As you can see in the second row the "begin" date was copied from the "begin" date of the first row since the 2 periods are overlapping for the same orsid. The length variable holds the number of months that are between the begin and end variable. You could add some code to only retain the maximum value of length by orsid.
Does this help ?
Mathias.
What do you want the output to look like?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.