BookmarkSubscribeRSS Feed
lovecoding
Calcite | Level 5

AETRT = 22459 
How I can it compare with this ?

AESTDTC = 2021-07-05

4 REPLIES 4
MayurJadhav
Quartz | Level 8

@lovecoding 

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
PaigeMiller
Diamond | Level 26

@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
JosvanderVelden
SAS Super FREQ

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;

 

Tom
Super User Tom
Super User

@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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 660 views
  • 0 likes
  • 5 in conversation