BookmarkSubscribeRSS Feed
NilsNoh
Calcite | Level 5

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!

2 REPLIES 2
Kurt_Bremser
Super User

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).

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 1782 views
  • 0 likes
  • 3 in conversation