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

I am trying to merge two datasets, data1 and data2, based on two variables, ID and date_month. In both datasets, the two variables have identical length, format and informat. However, the simple merge code as follows does not work, because the same ID-date_month show up as separate observations in the outcome.

 

data want;
	merge data1 data2;
	by ID date_month;
run;

I think the issue is with variable date_month. It is a YYMMN6. format variable converted from a YYMMDD10. date variable with command

date_month = date;
format date_month yymmn6.;

Is there any date feature in SAS that gives rise to my problem?

 

P.S.: It worked perfectly if I convert date as follows

date_month = intnx('month', date, 0, 'e');

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

You gave the answer to your own question:

 

 It worked perfectly if I convert date as follows

DATE_MONTH = intnx('month', DATE, 0, 'e');

 

The values are not the same. They are displayed the same when using a format that only shows the month, but one is a day somewhere in the month while the other is the last day.

 

1. To show the actual value, format as date9.

 

2. To merge, align the values or use proc sql: 

join ...  on intnx('month', data1.DATE, 0, 'e') = intnx('month', data2.DATE, 0, 'e');

 

 

View solution in original post

1 REPLY 1
ChrisNZ
Tourmaline | Level 20

You gave the answer to your own question:

 

 It worked perfectly if I convert date as follows

DATE_MONTH = intnx('month', DATE, 0, 'e');

 

The values are not the same. They are displayed the same when using a format that only shows the month, but one is a day somewhere in the month while the other is the last day.

 

1. To show the actual value, format as date9.

 

2. To merge, align the values or use proc sql: 

join ...  on intnx('month', data1.DATE, 0, 'e') = intnx('month', data2.DATE, 0, 'e');

 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1 reply
  • 1940 views
  • 0 likes
  • 2 in conversation