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
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?
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. ;
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?
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.