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

Hello, 

 

This looks like a simple thing to do, but I'm having a hard time to find an easy solution. 

 

I know this works (specifying exact date):

if '10Apr2008'd <= dob then test=1...

 

What I want to do is to specify only year and month;

Suppose I already converted dob to year/month format (dob2)...

How can do (this is not a programming language) 'if 10Apr < dob2 then text=1? 

 

I appreciate your suggestions. 

Thank you, 

 

Yoko

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

You ahve to make an assumption if you want to use only year and month. The assumption is that you use always the first day of the month, or the 15th day of the month, or the last day of the month.

--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

You ahve to make an assumption if you want to use only year and month. The assumption is that you use always the first day of the month, or the 15th day of the month, or the last day of the month.

--
Paige Miller
Shmuel
Garnet | Level 18

If dob2 is a char type variable formated yymm try

 

if put(dob, yymmn4.) <= dob2 then ...

 

pay attention, let date = '07DEC2018'd then

   put(date, yymmn6.) = '201812';  /* n stands for number */

   put(date, yymms7.) = '2018/12';  /* s stands for slash */ 

  

  

ballardw
Super User

@Yoko wrote:

Hello, 

 

This looks like a simple thing to do, but I'm having a hard time to find an easy solution. 

 

I know this works (specifying exact date):

if '10Apr2008'd <= dob then test=1...

 

What I want to do is to specify only year and month;

Suppose I already converted dob to year/month format (dob2)...

How can do (this is not a programming language) 'if 10Apr < dob2 then text=1? 

 

I appreciate your suggestions. 

Thank you, 

 

Yoko

 

 

 


How did you create dob2?

You question seems to relate to month and year but the shown pseudocode is comparing dob2 to a day of month and month value.

 

You may be better off sticking with a date and use the month and year functions. You should provide some concrete examples of your dob variables, some comparisons and the desired results. We can't tell if your DOB2 might be numeric or text, formatted as a date or not and whether the reduction to dob2 should consider the beginning of the month or the end of the month in the comparison.

 

I might guess that want some variation on intnx('month', dob,0,'B') (beginning of month) or  intnx('month', dob,0,'E') (end of month) instead of creating a new variable.

Reeza
Super User
What is the type and format of the variable you're working with here? Can you post a small data set with the expected output?
SuryaKiran
Meteorite | Level 14

What do you mean by converted to month year? Did you convert it to character representing as mmmyy or you just applied format to see them as mmmyy format.

 

If your just applying only the format than behind the screens it still holds the date value. You can still use full date value to filter ('01jan2018'd ). Make sure you use the proper boundaries for filtering. 

Thanks,
Suryakiran

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 1082 views
  • 0 likes
  • 6 in conversation