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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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