Skip to content
Prev 106446 / 398513 Next

R Version Problem in using write.foreign+SAS

Shubha,
On Dec 20, 2006, at 10:54 PM, Shubha Vishwanath Karanth wrote:

            
I tend not to change originals if I can help it, so I would create my 
own
version and call it writeForeignSAS2 as follows:

### Make a copy and write it out
writeForeignSAS2 <- foreign:::writeForeignSAS
dump("writeForeignSAS2", "writeForeignSAS2.R")
### Now make desired changes to the new version and then
### source it in
source("writeForeignSAS2.R")

### call write.foreign and specify your particular 'package'
write.foreign(df, datafile, codefile, package = "SAS2", ...)
Probably not. As of SAS 9.13, the date part of a datetime
that SAS reads in has to be of the form ddmmmyy or ddmmmyyyy. That's
why this format is used in writeForeignSAS.  (I could joke about SAS
saving more flexible datetime formats and informats for version 10.)

Some more specifics below.
This is the only format for datetime variables SAS will understand.
In earlier versions of writeForeignSAS, the 'datafile' was written
out this way but the 'codefile' didn't treat the variable as a
datetime variable.

If you want the data written out in a certain format, you can
convert the variable to character with

d$mydatetime <- format(d$mydatetime)

But this means that the 'codefile' will tell SAS to read
the variable in as a character variable.
Stephen Weigand
Rochester, Minnesota, USA