BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
WilliamB
Obsidian | Level 7

 

 

Hello,

I would like to create a table, with the information from Table 1, but I do not want individuals who are not present in Table 2. In sql code.

Thanks for your help. 

 

Table1    Table2 
       
ID Name   ID Age
14rt   159
15fd   171
16gf   182
17sq   193
18pm     
19er     
20tr     
21ea     
       
Want      
       
ID Name     
15fd     
17sq     
18pm     
19er     
       
       
1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26
proc sql;
  create table want as 
  select * from table1 where id not in (select id from table2);
quit;

Post test data in the form of a datastep in future please.

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26
proc sql;
  create table want as 
  select * from table1 where id not in (select id from table2);
quit;

Post test data in the form of a datastep in future please.

PeterClemmensen
Tourmaline | Level 20

Provided that your data is properly sortet...

 

data have1;
input ID $ Name $;
datalines;
14 rt
15 fd
16 gf
17 sq
18 pm
19 er
20 tr
21 ea
;

data have2;
input ID $ Age;
datalines;
15 9
17 1
18 2
19 3
;

data want;
    merge have1 have2(in=ina);
    by ID;
    if ina;
    keep ID Name;
run;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 936 views
  • 1 like
  • 3 in conversation