Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

datetime - sas7bdat date format to R date format

I loaded a sas7bdat file using the sas7bdat package, but the dates are converted to a num like this:

sas <- c(16922, 17045, 17014, 16983)

I tried

rPOSIX <- as.POSIXct(sas,origin='1960-01-01')

as mentioned here but it's wrong. I don't have access to SAS but the dates should be around the year 2006.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As my previous comment, here is a working example, where the origin argument is set like that because of a specific SAS setting, which sets the origin date to 1960-01-01, here informations:

 as.Date(sas, origin = "1960-01-01")
[1] "2006-05-01" "2006-09-01" "2006-08-01" "2006-07-01"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
...