BookmarkSubscribeRSS Feed
lnb001
Calcite | Level 5
I am trying to merge table 1 with table 2; however, table 1 has a visit # field and lab date fields, while table 2 only has an event date field. I want the merged table to show all labs that have a specific value at a certain visit and also include any corresponding events that happen on that same day or close to that date. The problem is an event date might be different than a lab date. Currently my table looks like this:

VISNO LAB EVENT
00 aa, bb xxxxxxxx
01 aa, ab xxxxxxxx

Because I can't merge by a common variable other that patient ID, the EVENT field repeats whenever there is more than one lab record. What I really want the table to look like is this:

VISNO LAB EVENT
00 aa, bb xxxxxxxx
01 aa, ab

Is there anyway to keep the events from repeating whenever there are multiple lab records?

Thanks.
2 REPLIES 2
Ksharp
Super User
It would be helpful that you need to post some dummy data and what you want your output to look like. It is hard to guess your intention.


Ksharp
Doc_Duke
Rhodochrosite | Level 12
I agree with KSharp, the narrative and the examples are confusing. Particularly as the narrative seems to be missing variables and you have 3 heading and 4 pieces of data in the sample.

Reading between the lines, I generally attack this sort of problem with PROC SQL. The idea of a "fuzzy" match or "nearest" match on dates is a natural for the BETWEEN operator on a JOIN. There are good examples of this in the SQL reference manual as well as in several BBUs.

Doc Muhlbaier
Duke

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 866 views
  • 0 likes
  • 3 in conversation