BookmarkSubscribeRSS Feed
Calcite | Level 5

## Convert character values to date

AETRT = 22459
How I can it compare with this ?

AESTDTC = 2021-07-05

4 REPLIES 4
Quartz | Level 8

## Re: Convert character values to date

Your question is not clear. Though I'd recommend to look at this SAS Date format

Here is how you can check formatted date values:

``````data test;
format AETRT_Formatted yymmdd10.;
AETRT = 22459 ;
AETRT_Formatted = AETRT;
run;
``````

You can also use PUT function if this is something you want to achieve:

``AETRT_Formatted=put(AETRT,yymmdd10.);``
Mayur Jadhav
BI Developer. Writer. Creative Educator.

SAS Blog → https://learnsascode.com
YouTube Channel: → https://www.youtube.com/@imayurj
Diamond | Level 26

## Re: Convert character values to date

@lovecoding wrote:

AETRT = 22459
How I can it compare with this ?

AESTDTC = 2021-07-05

Is AETRT numeric or character? Is AESTDTC really a character variable, or is it numeric with a format? Please check PROC CONTENTS and determine if each of these variables is numeric or character. Let us know.

--
Paige Miller
SAS Super FREQ

## Re: Convert character values to date

To understand more about dates and times in SAS you can read:

For a way to compare see the following code:

``````data _null_;
date1 = 22459;
date2 = mdy(5, 7, 2021);
days_between_1_2 = intck('day', date1, date2);
days_between_2_1 = intck('day', date2, date1);
formatted_date1 = date1;
formatted_date2 = date2;
format formatted_date1 formatted_date2 date9.;
put date1= '|'  formatted_date1= /
date2= '|'  formatted_date2= /
'days_between date1 and date2 is ' days_between_1_2 /
'days_between date2 and date1 is ' days_between_2_1;
run;``````

Super User

## Re: Convert character values to date

@lovecoding wrote:

AETRT = 22459
How I can it compare with this ?

AESTDTC = 2021-07-05

Assuming that the variable whose name ends with the letter C is a CHARACTER variable you can convert its contents to a date value using the INPUT() function.  Looks like the string is in a style that the YYMMDD informat can read.

To have the numeric value print in the same style attach the YYMMDD format to the it.

``````data want;
set have;
difference = aetrt - input(aestdtc,yymmdd10.);
format aetrt yymmdd10.;
run;``````

Result

```Obs         AETRT     AESTDTC      difference

1     2021-06-28    2021-07-05        -7

```
Discussion stats
• 4 replies
• 524 views
• 0 likes
• 5 in conversation