BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I have a table A, containing individuals with variables ID(=identity) and seven other variables, VAR1-VAR7.

VAR1 can have the values 0, 1 or 2.

From table A, I want to make two other tables, B and C.

In B I want all records where VAR1=0. That is easy to get.

In C I want all records for the individuals not found in B.

Concerning number of records this means that B+C le A, because the individuals found in B could also have records in A, where VAR1=1 or VAR1=2.

How do I get C?
2 REPLIES 2
FredrikE
Rhodochrosite | Level 12
proc sql;
create table_c as
select *
from table_a
where id not in (select distinct id from table_b)
;
quit;
deleted_user
Not applicable
data b c;
set a;
if var1=0 then output b;
else output c;
run;

Oops, not. too quick to answer. C could have the other var1=1 and var1=2 records for people in B.

So a second step is reqquired.
could use proc sql with not in as above or "not exist".
Could also use

proc sort data=b; by id;
proc sort data=c; by id;

data c;
merge b(in=inb) c(in=inc);
by id;
if inc and not inb then output;
run;

but I think the sql is the better way to go. Message was edited by: Chuck

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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