BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
alepage
Barite | Level 11

Hello,

 

I have two datasets.  In the first one, the var date1 as the date format 23dec2020 while in the other dataset, the date2 as the following date format : 2020-12-23 (yyyy-mm-dd).  

 

How can I bring back both to numerical value ex; 22272 in order to compare both dataset.

Regards,

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Date2 is not a SAS date value, nor is it formatted as YYYY-MM-DD.

 

Date2 is 2020 minus 12 minus 23, which is ... well you do the math.

 

If you want Date 2 to be a SAS date value, you should use this:

 

date2=input('2020-12-23',yymmdd10.);
--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

According to PROC CONTENTS, is date1 character or numeric? According to PROC CONTENTS, is date2 character or numeric?

--
Paige Miller
alepage
Barite | Level 11
it seems that they are both numeric but not using the same format
PaigeMiller
Diamond | Level 26

For numeric variables, format doesn't matter when you compare variables.

 

if date1<date2 then ... ;

works regardless of format. Formats just change the appearance, they don't affect the actual date values.

--
Paige Miller
alepage
Barite | Level 11
data test;
date = '23dec2020'd;
date2=2020-12-23;/*yyyy-mm-dd*/
if date1 eq date2 then
do;
flag=1;
end;
else
do;
flag=0;
end;
run;
alepage
Barite | Level 11
data test;
date1 = '23dec2020'd;
date2=2020-12-23;/*yyyy-mm-dd*/
if date1 eq date2 then
do;
flag=1;
end;
else
do;
flag=0;
end;
run;

The flag value should gives one...
PaigeMiller
Diamond | Level 26

Date2 is not a SAS date value, nor is it formatted as YYYY-MM-DD.

 

Date2 is 2020 minus 12 minus 23, which is ... well you do the math.

 

If you want Date 2 to be a SAS date value, you should use this:

 

date2=input('2020-12-23',yymmdd10.);
--
Paige Miller

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 6 replies
  • 1804 views
  • 0 likes
  • 2 in conversation