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

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
novinosrin
Tourmaline | Level 20
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 

View solution in original post

8 REPLIES 8
novinosrin
Tourmaline | Level 20
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 

ed_sas_member
Meteorite | Level 14

Hi @noda6003 

 

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;
Tom
Super User Tom
Super User

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';
noda6003
Quartz | Level 8

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

Kurt_Bremser
Super User

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;
novinosrin
Tourmaline | Level 20

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


 

ed_sas_member
Meteorite | Level 14

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1316 views
  • 5 likes
  • 5 in conversation