BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
westbestern
Obsidian | Level 7

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;
1 ACCEPTED SOLUTION

Accepted Solutions
tarheel13
Rhodochrosite | Level 12
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. 

View solution in original post

6 REPLIES 6
Reeza
Super User
/* 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;

 

tarheel13
Rhodochrosite | Level 12

I think @westbestern meant the flag is dthdtf='M' when month is imputed.

tarheel13
Rhodochrosite | Level 12

what are you imputing month and day to when both are missing? show us the imputation rules. 

westbestern
Obsidian | Level 7
Sorry about that! When month and day are missing, I impute January 1st
tarheel13
Rhodochrosite | Level 12

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.

tarheel13
Rhodochrosite | Level 12
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. 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2774 views
  • 0 likes
  • 3 in conversation