DATA Step, Macro, Functions and more

imcomplete datetime values like "2013-12-16 08:" cause missing values

Accepted Solution Solved
Reply
Super Contributor
Posts: 312
Accepted Solution

imcomplete datetime values like "2013-12-16 08:" cause missing values

I have a datetime variable with values like "2014-02-10 01:11:50". They were imported as $19. I tried to use "usedate= yes", but it gave error message.

So I tried to change the datetime format after imported in as $19.  format, and then using the following codes to convert to datetime.:

 

     registration_time =input(registration_timestamp,anydtdtm.);
     format registration_time datetime19.;

 

however, some values are imcomplete, like "2013-12-16 08:", and in this case, the new varible registration_time was set to missing.

 

How can I avoid the missing values? actually i do not need the hh:mm:ss part, and I checked the data and all imcomplete ones are in the hh:mm:ss part.

 

Thanks

 


Accepted Solutions
Solution
‎12-23-2015 02:48 PM
Super User
Super User
Posts: 6,500

Re: imcomplete datetime values like "2013-12-16 08:" cause missing values

241  data x;
242    registration_timestamp='2013-12-16 08:';
243    registration_date =input(registration_timestamp,yymmdd10.);
244    format registration_date yymmdd10. ;
245    put (_all_) (=);
246  run;

registration_timestamp=2013-12-16 08: registration_date=2013-12-16
NOTE: The data set WORK.X has 1 observations and 2 variables.

Perhaps the values have leading spaces?

What happened when you used the SCAN() function?

Perhaps that is not a space between the day and the hour, but some other character?  Perhaps that is not a hyphen but some other character?

 

View solution in original post


All Replies
Super User
Super User
Posts: 6,500

Re: imcomplete datetime values like "2013-12-16 08:" cause missing values

If the values always have 10 digits of date values then juse a different INFORMAT.

registration_date =input(registration_timestamp,yymmdd10.);
format registration_date yymmdd10. ;

If the date part might be shorter because of single digit month and/or day then you migth first need to eliminate the time part.

registration_date =input(scan(registration_timestamp,1,' '),yymmdd10.);
format registration_date yymmdd10. ;
Super Contributor
Posts: 312

Re: imcomplete datetime values like "2013-12-16 08:" cause missing values

when I used
registration_date =input(registration_timestamp,yymmdd10.);
format registration_date yymmdd10. ;

all registration_date values became missing values.
Solution
‎12-23-2015 02:48 PM
Super User
Super User
Posts: 6,500

Re: imcomplete datetime values like "2013-12-16 08:" cause missing values

241  data x;
242    registration_timestamp='2013-12-16 08:';
243    registration_date =input(registration_timestamp,yymmdd10.);
244    format registration_date yymmdd10. ;
245    put (_all_) (=);
246  run;

registration_timestamp=2013-12-16 08: registration_date=2013-12-16
NOTE: The data set WORK.X has 1 observations and 2 variables.

Perhaps the values have leading spaces?

What happened when you used the SCAN() function?

Perhaps that is not a space between the day and the hour, but some other character?  Perhaps that is not a hyphen but some other character?

 

Super Contributor
Posts: 312

Re: imcomplete datetime values like "2013-12-16 08:" cause missing values

Hi Tom

Yes, it works. Not sure what I did yesterday, but today when I came back to office and tested again, and it works.

Thank you very much!
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 174 views
  • 0 likes
  • 2 in conversation