BookmarkSubscribeRSS Feed
SASUserWhoNeedHelp
Calcite | Level 5
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!

8 REPLIES 8
SASUserWhoNeedHelp
Calcite | Level 5

I don't know which SAS time format to use for this date and time column. Thank you!

SASUserWhoNeedHelp
Calcite | Level 5

This column was  imported from Excel file, text only, $19..

Fugue
Quartz | Level 8

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;

Jagadishkatam
Amethyst | Level 16

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

Thanks,
Jag
Fugue
Quartz | Level 8

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.

Jagadishkatam
Amethyst | Level 16

Yes, i believe text cannot be used to subset the condition especially when the subsetting condition is related to date time.

Thanks,
Jag
Fugue
Quartz | Level 8

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.

Fugue
Quartz | Level 8

Are these numeric values (with a SAS format) or text?

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

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.

Discussion stats
  • 8 replies
  • 1740 views
  • 0 likes
  • 3 in conversation