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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 306 views
  • 0 likes
  • 2 in conversation