Solved
Contributor
Posts: 55

# date conversion

data have;

aestdtc="02mar2010";

aeendtc="03jul2010";

end;

how to convert these dates like 02-03-2010 and 03-07-2010?

thanks

Accepted Solutions
Solution
‎02-25-2017 11:02 PM
Posts: 5,626

## Re: date conversion

[ Edited ]

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;``````

PG

All Replies
Posts: 1,399

## Re: date conversion

[ Edited ]

Just as   x=3   assigns a numeric literal (3) to x

and

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.

Contributor
Posts: 55

## Re: date conversion

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

Posts: 1,399

## Re: date conversion

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.

Solution
‎02-25-2017 11:02 PM
Posts: 5,626

## Re: date conversion

[ Edited ]

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;``````

PG
Contributor
Posts: 55

## Re: date conversion

thanks it works for full date but not working where aestdtc="mar2014"if day is misssing

Posts: 1,399

## Re: date conversion

You didn't mention that.  Before I respond, are there other incoming date formats that you will need to accomodate?

Contributor
Posts: 55

## Re: date conversion

sorry didnt mention it.thr r few dates in which month and day is missing

Posts: 5,626

## Re: date conversion

What date to you want to convert aestdtc="mar2014" into?

PG
☑ This topic is solved.