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

Say I have a variable 'ReadTime' with the format datetime22.3, how to add the where statement to get the subset.

 

say I have

 

data want;

set exist;

where readtime>'01DEC2018:00:40:00.000';

run;

 

Then sas reports  'WHERE clause operator requires compatible variables'. Any idea? Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

will this work?

 


data want;

set exist;

where readtime>'01DEC2018:00:40:00.000'dt

run;

View solution in original post

10 REPLIES 10
novinosrin
Tourmaline | Level 20

will this work?

 


data want;

set exist;

where readtime>'01DEC2018:00:40:00.000'dt

run;
liyongkai800
Obsidian | Level 7
Though I've no idea why simply add 'dt then it works lol, it works indeed. Thanks.
liyongkai800
Obsidian | Level 7
Very informative, thanks.
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Look at the manual on the topic named literals.  It is system for passing in character data in a specific format, which SAS can convert on the fly.  So a suffix of:

'ddmmmyyyy'd    = date in form ddmmmyyyy
dt              = date time as given in the example
'...'n          = named literal of a column from third party software such as 
                  Excel where name may not be SAS conformant.
liyongkai800
Obsidian | Level 7
Yes, it works.
novinosrin
Tourmaline | Level 20

Thank you @liyongkai800

VarunD
Obsidian | Level 7

Hi,

I am trying to compare a datetime variable using the following expression

 

where eff_dt>'01DEC2018:00:00:00.000'dt

 

but it is throwing me an error

 

I tried 

where eff_dt > today( ) 

but this didn't work either.

 

Format of eff_dt is DateTime22.3 and values are like 31DEC2199:00:00:00.000

 

What am I doing wrong here ?

 

Thanks

Varun

 

 

novinosrin
Tourmaline | Level 20

ok, If your eff_dt is a datetime variable i.e the internal value is stored in seconds and you want to compare with today() an integer date, You would need to extract the the integer date from the datetime value using datepart

For example

 

if datepart(eff_dt)>today() ;/*assuming your eff_dt is a datetime value*/

 

if both are date values, i.e the internal value is stored as integers as the number of days from jan1,1960 you could use

 

if eff_dt>today()  /*both being date values with integers*/

 

HTH & Regards!

 

 

 

 

VarunD
Obsidian | Level 7

This worked !

You are a life saver. Thanks a ton.

 

Varun

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
  • 10 replies
  • 1638 views
  • 3 likes
  • 5 in conversation