BookmarkSubscribeRSS Feed
zdassu
Quartz | Level 8

Hi I am trying to bring back data between two dates using the today() function. I don't think I can do this in Data step but is there an equivalent that I can use. See code that I have created below

data work.tempA;
keep Name_Id Address_Id;
set work.tempb;
WHERE is_current_flg = 1 AND record_deleted_flg = 0
AND today()between Valid_From_Dt and Valid_To_Dt;
run;
6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20
data work.tempA;
keep Name_Id Address_Id;
set work.tempb;
WHERE is_current_flg = 1 AND record_deleted_flg = 0
AND Valid_From_Dt le today() le Valid_To_Dt;
run;
zdassu
Quartz | Level 8

Hi I tried that code but it does not bring back any records at all, the results table is blank

Tom
Super User Tom
Super User

Can you find an example that you think it should have found?

Please show the example data that fails to get selected but that you think it should select.

 

Make sure that the variables in your dataset are DATES (not strings, not datetime values, not numbers that humans might mistake for dates).

Tom
Super User Tom
Super User

Did it not work?  If so how? Did you get an error?  Not get the expected results?  Show example data that you though met the WHERE condition and didn't get selected (or the reverse).

Kurt_Bremser
Super User

Maxim 3: Know Your Data.

Are valid_from_dt and valid_to_dt SAS date values (numeric, with a date format attached)? If yes, run a proc freq on those columns to see which values they contain.

Reeza
Super User
TODAY() returns today's date, of July 17. Are you sure that's what you want to be doing?

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 6 replies
  • 1113 views
  • 0 likes
  • 5 in conversation