BookmarkSubscribeRSS Feed
Yamunanz2019
Calcite | Level 5
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
11 REPLIES 11
PaigeMiller
Diamond | Level 26

@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).

--
Paige Miller
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

See:
https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

About getting your data usable.

novinosrin
Tourmaline | Level 20

is that date16. or datetime16.?

Yamunanz2019
Calcite | Level 5
Datetime16.

And it is numeric
Yamunanz2019
Calcite | Level 5
The above mentioned solution is not working. It is returning zero records
novinosrin
Tourmaline | Level 20

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
Calcite | Level 5
Can someone suggest a solution please
PaigeMiller
Diamond | Level 26

@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. 

--
Paige Miller
FreelanceReinh
Jade | Level 19

@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;
Tom
Super User Tom
Super User

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.

Yamunanz2019
Calcite | Level 5
Thank you. It worked.👍

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

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
  • 11 replies
  • 2148 views
  • 2 likes
  • 6 in conversation