- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 09-07-2010 03:32 PM
(3244 views)
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!
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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]
when you use the following what happens?
[pre]
put myval= datetime20.;
[/pre]
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Scott Barry
SBBWorks, Inc.
Suggested Google advanced search argument, this topic / post:
import stata dta datetime site:sas.com