Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7664999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:26:53+00:00 2026-05-31T14:26:53+00:00

I have two datasets need to merge. The first one is a big dataset

  • 0

I have two datasets need to merge.

The first one is a big dataset with studyid and discharg(the date when the patients got their discharge).

The second one is the fewer observations than first one. They have two columns: studyid and call_mad(the date when nurse call the patient after discharge date). Not all discharges get a call from nurse.

The first table is

STUDYID   DISCHARG      

10011   2008-10-29          

10011   2008-11-7           

10011   2008-11-18          

10011   2009-10-17     

10011   2010-1-2       

10011   2010-1-22  

The second table is

 STUDYID        CALL_MAD

 10011          2009-10-19
 10011          2010-1-25  

The final table I want

STUDYID   DISCHARG      CALL_MAD

10011   2008-10-29          

10011   2008-11-7           

10011   2008-11-18          

10011   2009-10-17      2009-10-19

10011   2010-1-2       

10011   2010-1-22       2010-1-25  

Hopefully, it is clear. Thanks in advance.

Jane

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:26:55+00:00Added an answer on May 31, 2026 at 2:26 pm

    I had the same idea as thelatemail, i.e. you first extract the latest DISCHARG date that is < (or possibly <=) each CALL_MAD date, then merge that data back to the original dataset. I think that is the best that can be done with the data structured as it is, although there is potential for this logic to break down (e.g. if the nurse’s call didn’t relate to the latest discharge). Ideally you would want to add the DISCHARG date column to the second table as a secondary key, so that it would be easy to join on STUDYID and DISCHARG date without making any assumptions.

    Anyway, here the code I used.

    data ds1;
    input STUDYID DISCHARG :yymmdd10.;
    format DISCHARG yymmdd10.;
    datalines;
    10011   2008-10-29
    10011   2008-11-7
    10011   2008-11-18
    10011   2009-10-17
    10011   2010-1-2
    10011   2010-1-22
    ;
    run;
    
    data ds2;
    input STUDYID CALL_MAD :yymmdd10.;
    format CALL_MAD yymmdd10.;
    datalines;
    10011   2009-10-19
    10011   2010-1-25
    ;
    run;
    
    proc sql;
    create table ds3 as select
    ds1.*,
    ds2.call_mad
    from ds1 inner join ds2 on ds1.studyid=ds2.studyid and ds2.call_mad>ds1.discharg
    group by ds1.studyid,ds2.call_mad
    having ds1.discharg=max(ds1.discharg);
    
    create table want as select
    ds1.*,
    ds3.call_mad
    from ds1 left join ds3 on ds1.studyid=ds3.studyid and ds1.discharg=ds3.discharg;
    quit;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

DESCRIPTION I have two datasets with information that I need to merge. The only
I have two datasets each with one data table pulled from different sources and
I have two datasets in a SQL Server 2008 reporting services report. I need
I have two big and small dataframes (actually dataset is very very big !).
i have two datasets and i need to compare these two datasets such that
I have two tables in a DataSet where the ID field on each is
I have two TDBLookupComboBox controls that I'd like to connect to the same dataset,
I have a large ADO.Net dataset and two database schemas (Oracle) with different constraints.
I have a dataset that has two tables in it. I want to do
Suppose I have a dataset with those two immortal tables: Employee & Order Emp

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.