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.
data want; set have; date1 = input(date,yymmdd10.); format date1 date9.
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.
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.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With