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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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