BookmarkSubscribeRSS Feed
sas_
Fluorite | Level 6

Hi i am having main table the incre table append to the main table
but while appending to the Main table based on pid and dt it should remove the older one
ex in main table pid a1 is there again in incr table again pid with a1 came but with diff no
so it should append to main table and remove the older one based on date

Main Table

Pid no Dt
a1  1  12jan2011
a2  2  12jan2011
a3  3  12jan2011


Incre Table
Pid no Dt
a1  5  18jan2011
a4  6  18jan2011
a5  7  18jan2011


Output
Pid no Dt
a1  5  18jan2011
a2  2  12jan2011
a3  3  12jan2011
a4  6  18jan2011
a5  7  18jan2011

1 REPLY 1
art297
Opal | Level 21

If your data are already sorted by pid, then you could just use:

data Main;

  informat dt date9.;

  input Pid $ no Dt;

  cards;

a1  1  12jan2011

a2  2  12jan2011

a3  3  12jan2011

;

data Incre;

  informat dt date9.;

  input Pid $ no Dt;

  cards;

a1  5  18jan2011

a4  6  18jan2011

a5  7  18jan2011

;

data Output;

  format dt date9.;

  update main incre;

  by pid;

run;

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