DATA Step, Macro, Functions and more

End date imputations in adams

Reply
Occasional Contributor
Posts: 17

End date imputations in adams

here iam trying this code :

 

 

/* End date Imputations */

data mh;
input usubjid $ 1-17 mhendtc $ 19-28;
cards;
SCL004-14001-9001 
SCL004-14001-9002 
SCL004-14001-9002 2003
SCL004-14001-9002 
SCL004-14001-9003 
SCL004-14001-9003 2004
SCL004-14001-9003 
SCL004-14001-9004 2006-11
SCL004-14001-9004 
SCL004-14001-9004 2010-04
SCL004-14001-9004 
SCL004-14001-9004 
SCL004-14001-9005 2002
SCL004-14001-9005 
SCL004-14001-9006 
SCL004-14001-9006 2011-09-17
;
run;


data _mh;
set mh;
format mhed yymmdd10.;
enday=input(substr(mhendtc,9,2),best.);
enmonth=input(substr(mhendtc,6,2),best.);
enyear=input(substr(mhendtc,1,4),best.);
if enday ne . and enmonth ne . and enyear ne . then mhed=mdy(enmonth,enday,enyear);
else if enday = . and enmonth = . then mhed=mdy(12, 31, enyear);
else if enday = . then mhed=intnx('month',mdy(enmonth,01,enyear),0,'E');
else if mhendtc=' ' then mhed=.;
run;

 

 

but iam getting this warning why?:

 

 

737 data _mh;
738 set mh;
739 format mhed yymmdd10.;
740 enday=input(substr(mhendtc,9,2),best.);
741 enmonth=input(substr(mhendtc,6,2),best.);
742 enyear=input(substr(mhendtc,1,4),best.);
743 if enday ne . and enmonth ne . and enyear ne . then mhed=mdy(enmonth,enday,enyear);
744 else if enday = . and enmonth = . then mhed=mdy(12, 31, enyear);
745 else if enday = . then mhed=intnx('month',mdy(enmonth,01,enyear),0,'E');
746 else if mhendtc=' ' then mhed=.;
747 run;

NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line)Smiley SadColumn).
10 at 744:45
NOTE: There were 16 observations read from the data set WORK.MH.
NOTE: The data set WORK._MH has 16 observations and 6 variables.
NOTE: DATA statement used (Total process time): 

 

 

Kindly give the suitable code pls...kudos in advance

Attachment
PROC Star
Posts: 8,150

Re: End date imputations in adams

Posted in reply to rajeshV89

You're trying to read (i.e. use substr) where there isn't data to read. The following would get around that:

data _mh;
  set mh;
  format mhed yymmdd10.;
  if countc(mhendtc,'-') eq 0 then mhed=mdy(12,31,input(mhendtc,8.)); 
  else if countc(mhendtc,'-') eq 1 then do;
    mhed=mdy(input(scan(mhendtc,2,'-'),8.),1,input(scan(mhendtc,1,'-'),8.));
    mhed=intnx('month',mhed,0,'E');
  end;
  else if countc(mhendtc,'-') eq 2 then do;
    mhed=mdy(input(scan(mhendtc,2,'-'),8.),input(scan(mhendtc,3,'-'),8.),input(scan(mhendtc,1,'-'),8.));
  end;
run;

Art, CEO, AnalystFinder.com

 

Occasional Contributor
Posts: 17

Re: End date imputations in adams

i need one column like this:

 

Capture4.JPG

Occasional Contributor
Posts: 17

Re: End date imputations in adams

still iam getting the note as:

 

NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line)Smiley SadColumn).
276 at 992:41

 

 

here iam providing the data for that:

PROC Star
Posts: 1,218

Re: End date imputations in adams

Posted in reply to rajeshV89

First of all, I do not see any warnings in your log? Only notes. There is a big difference.

 

I assume that you ask about the notes. The "Missing values were generated as a result of performing an operation on missing values." note appears because your substring functions return missing values which you then try to convert to a numeric value with the INPUT Function.

Occasional Contributor
Posts: 17

Re: End date imputations in adams

yeah..iam hurry i've wrongly typed that as warning instead of note..thanks for reminding

Super User
Posts: 9,924

Re: End date imputations in adams

[ Edited ]
Posted in reply to rajeshV89

When mhendtc is completely empty, you can't pull anything from it, no date and no year, so you will get missing values. You need to provide logic for such cases, eg define a default year.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Occasional Contributor
Posts: 17

Re: End date imputations in adams

Posted in reply to KurtBremser

hi..

 

i didn't get any logic for that...can u pls provide if any...

 

kudos in advance

 

Super User
Posts: 9,924

Re: End date imputations in adams

Posted in reply to rajeshV89

@rajeshV89 wrote:

hi..

 

i didn't get any logic for that...can u pls provide if any...

 

kudos in advance

 


If you have no clue what to do in such cases, then how should we? It's up to you alone (or those you work for) to define what to do in such cases. Once the logic is known, it can be put into SAS code.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Ask a Question
Discussion stats
  • 8 replies
  • 175 views
  • 1 like
  • 4 in conversation