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

I have a table of observations with associated purchase date and time in the datetime20. format. However, I cannot seem to search by a specific date and time, I can only try to pull the observation by putting boundaries (re: greater than or less than) on the date and time. Is there  a where function I can use to just to pull it directly?

 

I have:

obs    Purchasedate.                 Account

1          01Jun2024:19:48:02     A
2         01Jun2024:20:22:01     B
3         01Jun2024:20:30:08    C
4.        01Jun2024:20:50:06    D


Current code not working:
data temp;

set orders;

where purchasedate = ‘01Jun2024:20:30:08’dt;

run;

 

What I want to see in my result is Obs 3. However, it’s not pulling anything. 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Always (as in ALWAYS) post the complete log of the step that does not work as expected. The log is our #1 diagnostic tool, and there's a reason why Maxim 2 is second only to Maxim 1 (Read the Documentation).

Copy/paste the log text into a window opened with this button:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

 

If your code did not throw an ERROR because of the curly quotes, then you most likely have fractions of a second in your datetime values. Use the ROUND function to remove them.

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

You have to remove the curly quotes and use straight quotes.

 

data temp;
set orders;
where purchasedate = '01Jun2024:20:30:08'dt;
run;

 

Please  use code boxes from now on when you enter code. You click on the "little running man" icon and paste your code into the window that appears.

--
Paige Miller
Kurt_Bremser
Super User

Always (as in ALWAYS) post the complete log of the step that does not work as expected. The log is our #1 diagnostic tool, and there's a reason why Maxim 2 is second only to Maxim 1 (Read the Documentation).

Copy/paste the log text into a window opened with this button:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

 

If your code did not throw an ERROR because of the curly quotes, then you most likely have fractions of a second in your datetime values. Use the ROUND function to remove them.

ChickenLittle
Obsidian | Level 7

The rounding was the trick! And thanks for pointing out the insert code feature. Really appreciate it!

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 3 replies
  • 745 views
  • 2 likes
  • 3 in conversation