Hi everybody, i have a csv-file, containing dates in an akward sas format, where 31.12.1559 is -1, 1.1.1960 is 1, 2.1.1960 is 2 and so on (see http://www.sfu.ca/sasdoc/sashtml/lrcon/zenid-63.htm ). Is there any function in R to convert this into YYYY-M-D easily? Best, Felix Dr. rer. nat. Dipl.-Psych. Felix Fischer Institut für Sozialmedizin, Epidemiologie und Gesundheitsökonomie Charité - Universitätsmedizin Berlin Luisenstrasse 57 10117 Berlin Tel: 030 450 529 104 Fax: 030 450 529 902 http://epidemiologie.charite.de<http://epidemiologie.charite.de/> [[alternative HTML version deleted]]
On Jan 27, 2012, at 10:45 AM, Fischer, Felix wrote:> Hi everybody, > > i have a csv-file, containing dates in an akward sas format, where > 31.12.1559 is -1, 1.1.1960 is 1, 2.1.1960 is 2 and so on (see http://www.sfu.ca/sasdoc/sashtml/lrcon/zenid-63.htm > ). Is there any function in R to convert this into YYYY-M-D easily?Seems as though as.Date should do it, assuming that's a typo for the first date. You just need to change the default origin setting: > as.Date( c(-1,0,1), origin="1960-01-01") [1] "1959-12-31" "1960-01-01" "1960-01-02"> > Best, > Felix >-- David Winsemius, MD West Hartford, CT
Does this do what you want? sasf <- c('31.12.1959','1.1.1960','1.2.1960') dt <- as.Date(sasf, format='%d.%m.%Y') -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 1/27/12 7:45 AM, "Fischer, Felix" <Felix.Fischer at charite.de> wrote:>Hi everybody, > >i have a csv-file, containing dates in an akward sas format, where >31.12.1559 is -1, 1.1.1960 is 1, 2.1.1960 is 2 and so on (see >http://www.sfu.ca/sasdoc/sashtml/lrcon/zenid-63.htm ). Is there any >function in R to convert this into YYYY-M-D easily? > >Best, >Felix > >Dr. rer. nat. Dipl.-Psych. Felix Fischer >Institut f?r Sozialmedizin, Epidemiologie und Gesundheits?konomie >Charit? - Universit?tsmedizin Berlin >Luisenstrasse 57 >10117 Berlin > >Tel: 030 450 529 104 >Fax: 030 450 529 902 >http://epidemiologie.charite.de<http://epidemiologie.charite.de/> > > > [[alternative HTML version deleted]] >