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

Hi i was wanting to filter  based on 'MONYYYY' date condition in the where step 

I know about the default date filter condition 'DDMONYYY'd . But that does not help here .

any suggestions ? 

eg: 

'AUG2018'

'SEP2018'

1 ACCEPTED SOLUTION
6 REPLIES 6
Reeza
Super User

How are you trying to filter your data?

You need to either use the formatted value or change your filter to use a full date. 

 

where '01Jun2019'd <= date_filtered <= '30Jun2019'd;

where vvalue(date_filtered) = '01JUN'; *check case matches here;

where put(date_filtered, monyy5.) = '01JUN';*case must match, text comparison;


@dennis_oz wrote:

Hi i was wanting to filter  based on 'MONYYYY' date condition in the where step 

I know about the default date filter condition 'DDMONYYY'd . But that does not help here .

any suggestions ? 

eg: 

'AUG2018'

'SEP2018'


 

PaigeMiller
Diamond | Level 26

@dennis_oz wrote:

Hi i was wanting to filter  based on 'MONYYYY' date condition in the where step 

I know about the default date filter condition 'DDMONYYY'd . But that does not help here .

any suggestions ? 

eg: 

'AUG2018'

'SEP2018'


Your use of quotes around the date confuses the matter. SAS does not display the quotes when you look at dates, so why are you showing the quotes to us?

 

Are these numeric variables, formatted to appear as AUG2018? Or are they character strings in a character variable?

 

In either case, you can filter using a WHERE clause, but to do this properly we need to know if they are character or numeric variables.

--
Paige Miller
dennis_oz
Quartz | Level 8
they are numeric variables that habe the format applied to them.
PaigeMiller
Diamond | Level 26

@dennis_oz wrote:
they are numeric variables that habe the format applied to them.

 

The first line of code from @Reeza should work. Probably his other lines of code work as well.

--
Paige Miller
Kurt_Bremser
Super User

Maxim 3: Know Your Data.

Is the variable in question character or numeric? If it is numeric, it has the monyy7. format assigned and contains a valid SAS date value; you can directly compare it to a date literal.

If it is character, you need to convert it first.

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
  • 6 replies
  • 1938 views
  • 3 likes
  • 4 in conversation