BookmarkSubscribeRSS Feed
ysantosh18
Obsidian | Level 7

Hi,

 

Kindly help me, I want to pull required data from 2 dataset with a data step.

 

eg:

datasetA:

101 bike

102 car 

103 bike

104 car

 

datasetB:

105 car

101 bike 

102 car

 

I want to exclude the observations which are not in datasetB and in datasetA as follow

 

datasetC:

 

101 bike

102 car

103 bike

105 car

 

Note: here In C observation: 104 should be missed , and 105 should be there

 

Thanks in Advance

Santosh

 

14 REPLIES 14
art297
Opal | Level 21

Why is 103 bike in the desired set. Are you matching on one or both variables?

ysantosh18
Obsidian | Level 7

No, I want to keep the records of A and B and exclude the record which is not in B and in A

nehalsanghvi
Pyrite | Level 9

103 bike is one of two records not in B and in A, so why have you put it in your desired output dataset C?

LinusH
Tourmaline | Level 20
Perhaps it's because of long working week, but I don't get the logic. Perhaps if you describe the business requirement it would be a bit clearer.
Also, why data step if e.g. SQL is better suited?
Data never sleeps
ysantosh18
Obsidian | Level 7

Am working with Clinical data, for Subject Elements, I need to set them One by One, if they are not in datasetB, they are said to be Non-completers of the study, so I've to exclude those subjects from A

 

thanks

nehalsanghvi
Pyrite | Level 9

This will give you everyone from A who is also in B (i.e. excludes those from A who are not in B)

 

create table C as
select *
from A
where yourIDVar in (select yourIDVar from B);
ysantosh18
Obsidian | Level 7

thanks for, but it worked for records who are in both the datasets

 

thanks

Santosh

nehalsanghvi
Pyrite | Level 9

Let's break this down Santosh. You do not want those obs from A which are not in B, This throws out:

 

103 bike

104 car

 

You say you do want 105 car in dataset C:

 

In this case, are you simply not looking for the dataset B itself? What are we not getting?

nehalsanghvi
Pyrite | Level 9

Okay, so are you all set? You just need dataset B? There is no coding problem to solve?

ysantosh18
Obsidian | Level 7

Not like that, As I said have to exclude the records which are "not in B" and "in A", Have to keep the records which are "in B" and "not in A" 

 

art297
Opal | Level 21

Obviouslly, those of us reading this trhead don't understand what you are trying to do.

 

For each of the 4 records in data set c, separately, please explain why they were selected.

 

ysantosh18
Obsidian | Level 7

thanks all for your support!

I apologise for not being clear, My situation is like that!

 

Working with clinical data.

 

Let us take an example of Acadamic class,

class6 and class8

Class8 may have promoted students who are succeded, and class6 are striving for success, and if students not in class8 of class6 are said to be failures, and if there are individual students of both the classes are said to be succeeded.

 

still am not clear

No problem

 

thanks again

 

 

 

Yavuz
Quartz | Level 8
Your description is called as "left join".

proc sql;
create table dataset_c as
select dataset_a.*, dataset_b.*
from dataset_a LEFT OUTER
join dataset_b on dataset_a.student=table_b.student; quit;

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
  • 14 replies
  • 1161 views
  • 1 like
  • 5 in conversation