Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sas7bdat date format to R date format

Tags:

datetime

r

sas

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.

like image 403
spore234 Avatar asked Sep 14 '15 12:09

spore234


People also ask

How do I convert yymmdd10 to date9?

data want; set have; date1 = input(date,yymmdd10.); format date1 date9.

How do I read SAS7BDAT files?

To read in a SAS dataset just use a set statement. You could first use a LIBNAME statement define a libref that points to the folder with the SAS dataset in it and use that libref in your code. libname learn '/home/XXX/learn/'; data Sales; set learn.

What is SAS default date format?

SAS date values are written in a SAS program by placing the dates in single quotes followed by a D. The date is represented by the day of the month, the three letter abbreviation of the month name, and the year. For example, SAS reads the value '17OCT1991'D the same as 11612, the SAS date value for 17 October 1991.


1 Answers

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"
like image 127
SabDeM Avatar answered Oct 25 '22 18:10

SabDeM