🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Quartz | Level 8

## how to filter dates based on character isodate

I think i asked smiliar question but since a new question arised want to know how to filter on date with character date which is in "2017-02-16T14:25:10" format. i need to filter on date less than or equal to 10jan2019 based on character date.

I used the below but it didnt work

if input(chdt, is8601dt.) le 2019-01-10;

any help

1 ACCEPTED SOLUTION

Accepted Solutions
Tourmaline | Level 20

## Re: how to filter dates based on character isodate

``where input(chdt, yymmdd10.)<='10JAN2019'd;``

Hi @noda6003   Basically, the idea is to read the first 10 bytes of chars using the informat yymmdd10. as the pattern resembles year-month-date

8 REPLIES 8
Tourmaline | Level 20

## Re: how to filter dates based on character isodate

``where input(chdt, yymmdd10.)<='10JAN2019'd;``

Hi @noda6003   Basically, the idea is to read the first 10 bytes of chars using the informat yymmdd10. as the pattern resembles year-month-date

Meteorite | Level 14

## Re: how to filter dates based on character isodate

You can try this code:

``````data have;
input datec \$19.;
cards;
2017-02-16T14:25:10
;
run;

data want;
set have;
if datepart(input(datec,is8601dt.)) le '10JAN2019'd;
run;``````
Super User

## Re: how to filter dates based on character isodate

One nice thing about date strings in YYYY-MM-DD order is that they sort lexicographically in the same order as they do chronologically.

``if chdt le '2019-01-10';``
Quartz | Level 8

## Re: how to filter dates based on character isodate

what if the date is in char and is in "12 JAN 2019" format.

i tried where input(strip(chard),date9.) <= '12JAN2019'd; but it didnt work.

Any suggestions

Super User

## Re: how to filter dates based on character isodate

You use the wrong function; strip() removes leading and trailing blanks, but you want to remove all blanks, so use compress():

``````data have;
input chard \$11.;
datalines;
12 jan 2019
13 jan 2019
;

data want;
set have;
where input(compress(chard),date9.) <= '12JAN2019'd;
run;``````
Tourmaline | Level 20

## Re: how to filter dates based on character isodate

Hi @noda6003  For embedded blanks, just read 2 more bytes of chars, so instead of date9. , use date11.

Example:

``````data w;
k=input("12 JAN 2019",date11.);
format k date9.;
run; ``````

@noda6003 wrote:

what if the date is in char and is in "12 JAN 2019" format.

i tried where input(strip(chard),date9.) <= '12JAN2019'd; but it didnt work.

Any suggestions

Meteorite | Level 14

## Re: how to filter dates based on character isodate

You can replace the strip() function by the compress() function to remove blanks.

Indeed, the strip() function can only remove leading and trailing blanks.

The compress() function remove all blanks.

Super User

## Re: how to filter dates based on character isodate

You can also use

``if datepart(input(chdt,e8601dt.)) le input("2019-01-10",yymmdd10.);``
Discussion stats
• 8 replies
• 1316 views
• 5 likes
• 5 in conversation