DATA Step, Macro, Functions and more

WHERE statement in a MERGE statement

Reply
New Contributor
Posts: 3

WHERE statement in a MERGE statement

[ Edited ]

Hey Guys,

 

I have a problem, I want to merge 2 sas tables with some WHERE restrictions.

 

My code is as follows

 

data merged;

merge table1 (in=a (...) where=(month=""))

           table2(in=b (...) where=(month between "201706" and "201806 or last_month between "201706 and "201806"  and not                 anyalpha(PERSONAL_ID)));

by personal_id;

(...)

 run;

 

Somehow, the code doesn't get the anyalpha statement and thus can't merge the two tables. I think more work needs to be done within the second WHERE statement but not sure how to solve the problem.

 

When I sort out the IDs with alpha characters in a data step before the merger, it works out. But not within the merge statement

 

Cheers!

Super User
Posts: 10,574

Re: WHERE statement in a MERGE statement

As posted, your second where= dataset option has a problem because of missing quotes.

 

Please post some example data (data steps with datalines) that illustrate your issue (unless solving the missing quotes problem also solves your issue).

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Super User
Posts: 9,840

Re: WHERE statement in a MERGE statement

There are a few mistakes here:

1) missing quote from after 201806 in both instances

2) month (numeric) cannot be within a string

3) month (number 1-12) cannot be within a 2 year gap - which would need to know year.

Ask a Question
Discussion stats
  • 2 replies
  • 62 views
  • 0 likes
  • 3 in conversation