data have;
aestdtc="02mar2010";
aeendtc="03jul2010";
end;
how to convert these dates like 02-03-2010 and 03-07-2010?
thanks
Use the input function with SAS date informats (such as date9.) to convert strings to SAS dates, and make sure you associate a SAS date format (such as ddmmyyd10.) with SAS dates:
data have;
aestdtc="02mar2010";
aeendtc="03jul2010";
aestdt = input(aestdtc, date9.);
aeendt = input(aeendtc, date9.);
format aestdt aeendt ddmmyyd10.;
run;
proc print; run;
Just as x=3 assigns a numeric literal (3) to x
and
name='paddyb' assigns a character literal (paddyb) to name
aestdtc="02mar2010"d assigns a date literal ("02mar2010"d) to the variable AESTDTC, which now contains a sas date value.
You only have to assign one of many date formats (date9., yymmdd10. yymon7. ...) to see it displayed in human-interpretable form. In your case, assign the format ddmmyy10:
format aestdtc ddmmyyd10.;
Note: the trailing "d" in ddmmyyd10. represents a dash. There are other separators available.
Thanks for reply.Actually in my aestdtc have 100 obs and i want to convert all
so my question is how to apply 'aestdtc'd
Do you have 100 observations in a sas dataset, where aestdtc is a character variable? Show the input data set please, in the form of a sas data set or raw data file.
Use the input function with SAS date informats (such as date9.) to convert strings to SAS dates, and make sure you associate a SAS date format (such as ddmmyyd10.) with SAS dates:
data have;
aestdtc="02mar2010";
aeendtc="03jul2010";
aestdt = input(aestdtc, date9.);
aeendt = input(aeendtc, date9.);
format aestdt aeendt ddmmyyd10.;
run;
proc print; run;
thanks it works for full date but not working where aestdtc="mar2014"if day is misssing
You didn't mention that. Before I respond, are there other incoming date formats that you will need to accomodate?
sorry didnt mention it.thr r few dates in which month and day is missing
What date to you want to convert aestdtc="mar2014" into?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.