I have two data A and B with more than 500 observations like this :
data A :
ID NAME DATE
320 ANNA 12NOV2016
177 JOSH 14FEB2017
177 JOSH 16JAN2015
185 MIKE 03APR2017
185 MIKE 12FEB2017
190 ANGIE 12JAN2017
data B :
ID NAME
320 ANNA
177 JOSH
160 MAX
I want to find observations which are in A but are not in B and by keeping the most recent date. I mean how can I get something like this ? :
ID NAME DATE
185 MIKE 03APR2017
190 ANGIE 12JAN2017
Your previous question was also about most recent date. The solution there is similar here, first get the most recent and then filter your dataset, either via a LEFT SQL join or a MERGE, see below.
Assuming your data is sorted by name:
data want;
set name_dates names (In= InNames);
By Name;
if InNames;
run;
@John4 wrote:
I have two data A and B with more than 500 observations like this :
data A :
ID NAME DATE
320 ANNA 12NOV2016
177 JOSH 14FEB2017
177 JOSH 16JAN2015
185 MIKE 03APR2017
185 MIKE 12FEB2017
190 ANGIE 12JAN2017
data B :
ID NAME
320 ANNA
177 JOSH
160 MAX
I want to find observations which are in A but are not in B and by keeping the most recent date. I mean how can I get something like this ? :
ID NAME DATE
185 MIKE 12FEB2017
190 ANGIE 12JAN2017
Hi:
Just curious, how do you define "most recent". I see 2 dates for Mike -- one in April and one in Feb. I would consider the one in April to be "most recent", but in your desired output, you show the Feb date as the one you want. Can you clarify whether you want the earliest date (Feb) or the most recent date (April)?
cynthia
You're right. It was a typo, I edit the topic. I mean, MIKE <---> 03APR2017
Your previous question was also about most recent date. The solution there is similar here, first get the most recent and then filter your dataset, either via a LEFT SQL join or a MERGE, see below.
Assuming your data is sorted by name:
data want;
set name_dates names (In= InNames);
By Name;
if InNames;
run;
@John4 wrote:
I have two data A and B with more than 500 observations like this :
data A :
ID NAME DATE
320 ANNA 12NOV2016
177 JOSH 14FEB2017
177 JOSH 16JAN2015
185 MIKE 03APR2017
185 MIKE 12FEB2017
190 ANGIE 12JAN2017
data B :
ID NAME
320 ANNA
177 JOSH
160 MAX
I want to find observations which are in A but are not in B and by keeping the most recent date. I mean how can I get something like this ? :
ID NAME DATE
185 MIKE 12FEB2017
190 ANGIE 12JAN2017
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.