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

Hello,

 

My data looks something like this:

 

var1    var2

 1          2

 3          3

 1          3

 

I need to keep only the data points that match, such as when var1 and var2 both have a value of 3, and I can get rid of the rest of the data. How could I do this? 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
data want;
set have;
if var1=var2;
run;

@sdevenny wrote:

Hello,

 

My data looks something like this:

 

var1    var2

 1          2

 3          3

 1          3

 

I need to keep only the data points that match, such as when var1 and var2 both have a value of 3, and I can get rid of the rest of the data. How could I do this? 


 

View solution in original post

2 REPLIES 2
Reeza
Super User
data want;
set have;
if var1=var2;
run;

@sdevenny wrote:

Hello,

 

My data looks something like this:

 

var1    var2

 1          2

 3          3

 1          3

 

I need to keep only the data points that match, such as when var1 and var2 both have a value of 3, and I can get rid of the rest of the data. How could I do this? 


 

Kurt_Bremser
Super User

Since all values for the condition are contained in the incoming dataset, you can use WHERE in its different forms as statement, dataset option or SQL clause:

data want;
set have;
where var1 = var2;
run;

data want;
set have (where=(var1 = var2));
run;

proc sql;
create table want as
  select * 
  from have
  where var1 = var2
;
quit;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 352 views
  • 0 likes
  • 3 in conversation