BookmarkSubscribeRSS Feed
statadm
Fluorite | Level 6
I'm frequently having to move data back and forth from SAS to Stata or Stata to SAS. I know how to convert SAS Date/Time to Stata, but I cannot find a way to convert Stata Date/Time back to SAS.

Is there a known calculation to do this?

The variables come into SAS formatted as datetime18., but the time is incorrect. I used StatTransfer v11 to do this, but I also tried exporting from Stata and it still did not work.

My thought is that I will need to break this out into separate date and time variables and recalculate time and then put them back together.

Any ideas if this will work or if there is an easier option?

Thank in advance!
5 REPLIES 5
art297
Opal | Level 21
I'm not familiar with it, but you could try the following:

http://faculty.fuqua.duke.edu/home/blanc004/data_programming/sas_to_stata/savasas.html
or, in short form: http://xrl.us/bhyhck

It is a routine, from someone at Duke University, that supposedly converts stata files to sas files, including datetime variables.

Art
statadm
Fluorite | Level 6
Thank you for this link.

I was able to install it and run it with no problem. It did create the SAS database and it looks like dates formatted fine, but still the datetime variables did not convert correctly. I did try to format into datetime and all that I get is a long number, never a formatted datetime variable.
ArtC
Rhodochrosite | Level 12
When you say that the times did not convert correctly do you mean that they come out as 12:43 when they should be 13:35? or are they just not 'formatted'. Have you applied a datetime format? Datetime values are a large number (seconds since midnight of 01jan1960 - the start of time).

when you use the following what happens?
[pre]
put myval= datetime20.;
[/pre]
statadm
Fluorite | Level 6
Stata time is in milliseconds from 01jan1960 00:00:00.000 where 1 is one millisecond from that time. 01jan1960 00:00:00.001

When I try to format (datetime20.) it just doesn't work, I still get the long number in milliseconds. I realize now that I"m going to have to convert the milliseconds first (to seconds) and then format the datetime value.

Thanks for helping me realize this.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
With an output FORMAT of datetime20. you are telling SAS to truncate at the second -- suggest you first try using BEST. as an output format and you may see "seconds since 1/1/1960". Then explore using DATETIME format specified as datetime20.3 instead.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

import stata dta datetime site:sas.com

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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