BookmarkSubscribeRSS Feed
rajeshV89
Fluorite | Level 6

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):(Column).
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

9 REPLIES 9
art297
Opal | Level 21

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

 

rajeshV89
Fluorite | Level 6

i need one column like this:

 

Capture4.JPG

rajeshV89
Fluorite | Level 6

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):(Column).
276 at 992:41

 

 

here iam providing the data for that:

bsd70
Fluorite | Level 6

If leap year and month of February then end day (extra day)  should be 29 and not leap year and month of February then end day should be 28. Also, end of the day for January, March, May, July, August, October, December are 31 and end of the day for April, June, September, November are 30.

Code required update using leap year and month.

leapyear = (mod(year,4) = 0) and ((mod(year,100) ne 0) or (mod(year,400) = 0)); 

 

 

PeterClemmensen
Tourmaline | Level 20

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.

rajeshV89
Fluorite | Level 6

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

Kurt_Bremser
Super User

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.

rajeshV89
Fluorite | Level 6

hi..

 

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

 

kudos in advance

 

Kurt_Bremser
Super User

@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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 2065 views
  • 2 likes
  • 5 in conversation