I'm working on coding SDTM to ADaM and I want to create an imputation flag "M" when both month and day are missing (ex: 2014 instead of 2014-06-18) and create a new variable called DTHDT (date of death). I have an example below of what I did for a missing day. How do I go about doing this for a missing month and day?
/* if day is missing in dthdtc then do */
if length(dthdtc)=7 then do;
dthdt= input(strip(dthdtc) || '-01', yymmdd10.); *concatenating '-01' to the end of the character
date string and converting to numeric;
dthdtf='D'; *flag is 'D' when day is imputed;
end;
data have;
input dthdtc :$18.;
datalines;
2014
2014-06
2014-06-18
;
run;
data want;
set have;
format dthdt yymmdd10.;
year=scan(dthdtc,1,'-');
day=scan(dthdtc,3,'-');
mth=scan(dthdtc,2,'-');
if nmiss(year,day,mth)=0 then dthdt=input(catx('-',year,mth,day),yymmdd10.);
*only day missing;
if day='' and mth ne '' then do;
day='01';
dthdtf='D';
dthdt=input(catx('-',year,mth,day),yymmdd10.);
end;
*day and month both missing;
if day='' and mth='' then do;
day='01';
mth='01';
dthdtf='M';
dthdt=input(catx('-',year,mth,day),yymmdd10.);
end;
run;
you didn't tell us the imputation rules. I imputed day to '01' when it's missing and imputed both day and month to '01' when both are missing.
/* if day is missing in dthdtc then do */
if length(dthdtc)=7 then do;
dthdt= input(strip(dthdtc) || '-01', yymmdd10.);
*concatenating '-01' to the end of the character date string and converting to numeric;
dthdtf='D';
*flag is 'D' when day is imputed;
end;
Similarly?
/* if month& day is missing in dthdtc then do */
if length(dthdtc)=4 then do;
dthdt= input(strip(dthdtc) || '07-15', yymmdd10.);
*concatenating '07-15' to the end of the character date string and converting to numeric;
dthdtmnthf='D';
*flag is 'D' when month day is imputed;
end;
Why did you impute day as 1?
Typically for date imputations I've seen the 15th and July used as cutoffs for population/research statistics. It has something to do with allowing it to balance out over time but I suspect it's not too important.
@westbestern wrote:
I'm working on coding SDTM to ADaM and I want to create an imputation flag "M" when both month and day are missing (ex: 2014 instead of 2014-06-18) and create a new variable called DTHDT (date of death). I have an example below of what I did for a missing day. How do I go about doing this for a missing month and day?
/* if day is missing in dthdtc then do */
if length(dthdtc)=7 then do;
dthdt= input(strip(dthdtc) || '-01', yymmdd10.); *concatenating '-01' to the end of the character
date string and converting to numeric;
dthdtf='D'; *flag is 'D' when day is imputed;
end;
I think @westbestern meant the flag is dthdtf='M' when month is imputed.
what are you imputing month and day to when both are missing? show us the imputation rules.
Okay, that's the way I did it in the code I gave you. Please test it out and feel free to accept as solution if it works for you.
data have;
input dthdtc :$18.;
datalines;
2014
2014-06
2014-06-18
;
run;
data want;
set have;
format dthdt yymmdd10.;
year=scan(dthdtc,1,'-');
day=scan(dthdtc,3,'-');
mth=scan(dthdtc,2,'-');
if nmiss(year,day,mth)=0 then dthdt=input(catx('-',year,mth,day),yymmdd10.);
*only day missing;
if day='' and mth ne '' then do;
day='01';
dthdtf='D';
dthdt=input(catx('-',year,mth,day),yymmdd10.);
end;
*day and month both missing;
if day='' and mth='' then do;
day='01';
mth='01';
dthdtf='M';
dthdt=input(catx('-',year,mth,day),yymmdd10.);
end;
run;
you didn't tell us the imputation rules. I imputed day to '01' when it's missing and imputed both day and month to '01' when both are missing.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.