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?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.