SAS : Converting Text format to date format and finding difference between dates -
i new sas , have data set below:
payment 335861 36416 5 41641 41648 payment 335861 85610 8 41641 41648 payment 335861 99214 156 41641 41648
in last 2 columns dates in text format, kind when make tab delimited file excel.
now want convert these numbers date format. , find difference(in days) dates got. tried "informat" way not getting anywhere it.please help....
data sample_data; infile cards; input type $ id amount count tdate1 $ tdate2 $; cards ; payment 335861 36416 5 41641 41648 payment 335861 85610 8 41641 41648 payment 335861 99214 156 41641 41648 ; run; data out_data; set sample_data; format date1 date2 yymmdds10.; /* format=display number (of days) date */ date1 = input(tdate1, 5.);/* conversion text number (assuming it's sas date value=number of days 1jan1960 */ date2 = input(tdate2, 5.); datediff = date1 - date2; /* calculate date difference */ run;
example assumes "dates" come sas, meaning it's number of days since 1jan1960. mean value '41641' 3jan2074.
in case numbers come different data source , meaning different you'll have correction numbers/dates.
e.g. in excel '41641' 2.1.2014 (it's number of days since 1jan1900 + 1). conversion + adjustment needed in case be:
date1 = input(tdate1, 5.) - ('1jan1960'd - '1jan1900'd) - 2; date2 = input(tdate2, 5.) - ('1jan1960'd - '1jan1900'd) - 2;
Comments
Post a Comment