@Yamunanz2019 wrote:
Hi I have a columnX with date16.
Ex
X
22Sep17:11:30:22
22Sep17:11:32:11
I am writing sas code as
Data sample1;
Set sample;
Where x=‘‘22Sep17:11:30:22’’dt;
Run;
I am not able retrieve columns with 22Sep17:11:30:22.
Can you please help me where I am going wrong.
Thanks
Yam
This indicates to me that you have text in X, and not a valid SAS datetime. But really, we can't help further unless you show us your code you are using, and provide the input data as a SAS data step (and not in any other format).
Please review the post a question guidance, it is essential in almost every instance to provide data in the form of a runnable program. We can't see your computer, and "it does not work" does not tell us anything. This code for instance does work perfectly well:
data have; x="22Sep17:11:30:22"dt; output; x="22Sep17:11:32:11"dt; output; run; data sample1; set have; where x="22Sep17:11:30:22"dt; run;
About getting your data usable.
is that date16. or datetime16.?
Here is my test, please verify
data have;
input date :datetime16.;
format date datetime16.;
cards;
22Sep17:11:30:22
22Sep17:11:32:11
;
data want;
set have;
where date='22Sep17:11:30:22'dt;
run;
@Yamunanz2019 wrote:
Can someone suggest a solution please
You have to provide us a portion of your data (as SAS data step code, and not in any other form) for us to help you further.
@Yamunanz2019 wrote:
Can someone suggest a solution please
Decimal places (fractions of a second) can be the reason why the values of X differ slightly from what the DATETIME16. format displays. In this case rounding should work:
where round(x)='22Sep17:11:30:22'dt;
Two issues to check.
1) Your actual dates have fractions of seconds stored, so the values do not exactly match. Either round the values or use inequalities in your test.
2) Your actual dates are from a different century than the what you are testing for.
Display the values using DATETIME19. instead or DATETIME16. to see the full year. (there is a bug in the DATETIME format and you need to use 19 to get four digit years, even though it should fit in 18 characters.)
Display the values using DATETIME24.3 to see if there are fractions of seconds.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.