BookmarkSubscribeRSS Feed
WilliamB
Obsidian | Level 7

Hello, 

 

I have two table I want to remove the individuals from table 1 who are not present in table 2.
Thanks for your help.

 

 

Table 1  Table 2 
     
Nom Argent Nom F
Toto5 Williamo
Titi4 Mathiaso
Henru3   
Sophie4   
Didier6   
william3   
Nelson4   
Mathias 8   
     
     
     
     
Table 3    
     
Nom Argent   
william3   
Mathias 8   
2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20
data Table1;     
input Nom $ Argent;
datalines;
Toto 5
Titi 4
Henru 3
Sophie 4
Didier 6
William 3
Nelson 4
Mathias 8
;

data Table2;
input Nom $ F $;
datalines;
William o
Mathias o
;

proc sql;
    create table Table3 as
    select * from Table1
    where Nom in (Select distinct Nom from Table2);
quit;
PeterClemmensen
Tourmaline | Level 20

Or a data step approach

 

data Table3;
    if _N_=1 then do;
        declare hash h(dataset:'Table2');
        h.definekey('Nom');
        h.definedone();
    end;

    set Table1;

    if h.find()=0;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 729 views
  • 0 likes
  • 2 in conversation