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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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