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.
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:
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.
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.
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:
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.
The rounding was the trick! And thanks for pointing out the insert code feature. Really appreciate it!
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.
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.
Ready to level-up your skills? Choose your own adventure.