BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
fengyuwuzu
Pyrite | Level 9

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User
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

4 REPLIES 4
Tom
Super User Tom
Super User

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. ;
fengyuwuzu
Pyrite | Level 9
when I used
registration_date =input(registration_timestamp,yymmdd10.);
format registration_date yymmdd10. ;

all registration_date values became missing values.
Tom
Super User Tom
Super User
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?

 

fengyuwuzu
Pyrite | Level 9
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!

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
  • 4 replies
  • 832 views
  • 0 likes
  • 2 in conversation