1
votes

I read in a sas7bdat file using the haven package. One column has dates in the YYQ6. format.

I R this is converted to numbers like -5844, 0, 7121, .. How can I convert this to a year format? I have no access to SAS but these values should be birth dates.

2
how can you have quarterly birth dates?Dirk Nachbar
The column datatype is only involved in the visualisation of the data. But maybe they want to know how many People were born in each in each quarter of year... Who knows ;-)Umberto
@DirkNachbar It is a medical data set where the exact birth dates were blinded for privacy reasonsspore234

2 Answers

8
votes

Bit of Research first. SAS uses as Zero 1st of January 1960 (see http://support.sas.com/publishing/pubcat/chaps/59411.pdf) so if you want the year of the data (represented by your number) it should be

format(as.Date(-5844, origin="1960-01-01"),"%Y")

and you get in this case

1944

is that correct? is what you are expecting?

To learn more on the data type YYQ6. check this Support article from SAS

http://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm#n02xxe6d9bgflsn18ee7qaachzaw.htm

Let me know if is working.

Umberto

2
votes

I think in SAS dates are days from 1/1/1960, so you can do

sasq <- c(-5844, 0, 7121)
as.Date(sasq, '1960-01-01')
[1] "1944-01-01" "1960-01-01" "1979-07-01"