Hello SAS Community,
I have a methodology/coding question for my data.
The requirement is for a hospital to have at least 3 months of baseline data and 3 months of consecutive data to be included. There is a specified baseline period, but if they don't have enough data, it can be outside of the baseline period IF there's 3 consecutive months.
For example,
Hospital ID | 10/1/14 | 11/1/14 | 12/1/14 | 9/1/16 | 10/1/16 | 11/1/16 | 12/1/16 | 1/1/17 | 2/1/17 | 3/1/17 | 4/1/17 | 5/1/17 | 6/1/17 |
1 | . | . | . | . | Y | . | . | Y | Y | Y | Y | Y | . |
2 | . | . | . | Y | Y | Y | Y | Y | Y | Y | Y | Y | . |
3 | . | . | . | . | Y | Y | Y | Y | Y | Y | . | . | . |
4 | Y | Y | Y | Y | Y | Y | Y | . | . | . | . | . | . |
The baseline period is anything before September 2016. The performance period is anything after October 2016.
Hospital 1 has a total of 6 months of data, but cannot be included because there are only 5 months of consecutive data.
Hospital 2 has 9 months of data, but some of the consecutive months fall into the performance period, but it's ok IF there are at least 3 months of consecutive performance data following this hospital's baseline period.
The baseline and performance period for the hospitals would be:
Baseline | Performance | |
Hospital 1 | Not included | Not included |
Hospital 2 | 9/2016 - 11/2016 | 12/216 - 5/2017 |
Hospital 3 | 10/2016 - 12/2016 | 1/2017 - 3/2017 |
Hospital 4 | 10/2014 - 12/2014, 9/2016 | 10/2016 - 12/2016 |
What's the best way to code for this data?
Thank you for your help in advance.
Provide example data in the form of a data step. Since the "variables" you show are generally not valid SAS variable names you'll need to provide lots of information about your data set and the datastep is the best way.
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
Assuming your variables are: ID M1 M2 M3 ... Mn
and each Mi variable is a sas date variable, then -
you may try next code:
%let date1 = 01OCT2014;
%let date2 = 01JUN2017;
data want;
sey have;
date1 = input("&date1",date9.);
date2 = input("&date2",date9.);
count_baseline = 0;
count_performance = 0;
include = 0;
length baseline performance $20
base_start base_end perfm_start perfm_end 8;
array mx m1-m24; /* assuming 24 month data */
do i=1 to dim(mx);
if count_baseline ge 3 and
count_performance ge 3
then include =1;
if mx(i) = . and include = 0 then do;
count_baseline = 0;
count_performance = 0;
end;
else do; /* mx(i) = Y */
datex = intnx('month', date1, i-1);
if datex le '01sep2016'd then do;
if count_baseline = 0 then base_start = datex;
base_end = datex;
count_baseline +1;
end;
else do; /* datex ge '01OCT2016'd */
if count_performance = 0 then perfm_start = datex;
perfm_end = datex;
count_performance +1;
end;
end; /* ending loop over mx */
if include = 0 then do;
baseline = 'Not Included';
performance = 'Not Included';
end;
else do;
baseline = catx(' - ',put(base_start,yymms7.),
put(base_end,yymms7.));
performance = catx(' - ',put(perfm_start,yymms7.),
put(perfm_end,yymms7.));
end;
keep ID baseline performance;
run;
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 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.