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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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