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
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
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
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';
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
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;
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
Hi @noda6003
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.
You can also use
if datepart(input(chdt,e8601dt.)) le input("2019-01-10",yymmdd10.);
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.