Date |
2013-07-05 00:10:52 |
2013-07-05 00:10:50 |
2013-07-05 00:10:49 |
2013-07-04 22:04:44 |
2013-07-04 22:04:42 |
2013-07-04 22:04:39 |
2013-07-04 22:04:36 |
2013-07-04 22:04:34 |
2013-07-04 22:04:10 |
2013-07-04 21:06:19 |
How to keep the rows with date and time after 2013-07-04 21:06:19 in SAS? Thanks!
I don't know which SAS time format to use for this date and time column. Thank you!
This column was imported from Excel file, text only, $19..
Ideally, you should convert the text values to actual date values. However, something like the following should work?
%let mydate = 2013-07-04 21:06:19;
Data want ;
set your-file-name ;
where date >= "&mydate";
run;
Hi
as you mentioned that the date time values are in text format(characters). It is important to convert them into numeric format to make them work in the if condition. and at the same time the date with which you are going to use as the condition (2013-07-04 21:06:19) should also be in numeric.
so please try the below code
data _null_;
mydate= input("2013-07-04 21:06:19",ANYDTDTM20.);
call symput("mydate",mydate);
run;
%put &mydate;
the above code will create the macro variable which youare going to use as the condition.
the have dataset has the date times in text format, which i am converting into numeric format in another dataset, and passing the if condition.
data have;
input date & $20.;
cards;
2013-07-05 00:10:52
2013-07-05 00:10:50
2013-07-05 00:10:49
2013-07-04 22:04:44
2013-07-04 22:04:42
2013-07-04 22:04:39
2013-07-04 22:04:36
2013-07-04 22:04:34
2013-07-04 22:04:10
2013-07-04 21:06:19
;
data want;
set have;
ndate=input(date,ANYDTDTM20.);
format ndate datetime20.;
if &mydate < ndate ;
run;
Thanks,
Jagadish
The text-based comparison should still work in this case, provided all of the dates have a consistent form (YYYY-MM-DD HH:MM:SS) and the where clause contains a text value that is in the same form. But, I agree, a date conversion is preferable.
Yes, i believe text cannot be used to subset the condition especially when the subsetting condition is related to date time.
The text comparison should work in this case (number-like). There are no letters that would mess it up (for example: JAN, AUG). The ASCII and EBCDIC collating sequences will both evaluate the comparison correctly, I believe.
Are these numeric values (with a SAS format) or text?
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.